> ## Documentation Index
> Fetch the complete documentation index at: https://docs.remind.tools/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase API

> Supabase backend integration documentation

# Supabase API Documentation

Comprehensive guide for Supabase integration in Remind Tools.

## Configuration

### Environment Setup

```bash theme={null}
# .env.development
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_KEY=your-service-key # Server-side only
```

### Client Initialization

```dart theme={null}
import 'package:supabase_flutter/supabase_flutter.dart';

Future<void> initSupabase() async {
  await Supabase.initialize(
    url: Environment.supabaseUrl,
    anonKey: Environment.supabaseAnonKey,
  );
}

final supabase = Supabase.instance.client;
```

## Authentication

### Email/Password

```dart theme={null}
// Sign up
final response = await supabase.auth.signUp(
  email: 'user@example.com',
  password: 'password',
);

// Sign in
final response = await supabase.auth.signInWithPassword(
  email: 'user@example.com',
  password: 'password',
);
```

### Social Providers

```dart theme={null}
// OAuth sign in
await supabase.auth.signInWithOAuth(
  OAuthProvider.google,
  redirectTo: 'io.supabase.remind://login-callback',
);
```

## Database Operations

### CRUD Operations

```dart theme={null}
// Create
final data = await supabase
  .from('trips')
  .insert({'title': 'Paris Trip'})
  .select()
  .single();

// Read
final trips = await supabase
  .from('trips')
  .select('*, destinations(*)')
  .eq('user_id', userId);

// Update
await supabase
  .from('trips')
  .update({'title': 'Updated Title'})
  .eq('id', tripId);

// Delete
await supabase
  .from('trips')
  .delete()
  .eq('id', tripId);
```

## Real-time Subscriptions

```dart theme={null}
final subscription = supabase
  .from('trips')
  .stream(primaryKey: ['id'])
  .eq('user_id', userId)
  .listen((List<Map<String, dynamic>> data) {
    // Handle real-time updates
  });

// Clean up
await subscription.cancel();
```

## Edge Functions

### Deployment

```bash theme={null}
# Deploy function
supabase functions deploy trip-planner

# Invoke function
curl -X POST 'https://project.supabase.co/functions/v1/trip-planner' \
  -H 'Authorization: Bearer YOUR_ANON_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"destination": "Paris"}'
```

### Function Example

```typescript theme={null}
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'

serve(async (req) => {
  const { destination } = await req.json()
  
  // Process request
  const itinerary = await generateItinerary(destination)
  
  return new Response(
    JSON.stringify({ itinerary }),
    { headers: { 'Content-Type': 'application/json' } }
  )
})
```

## Storage

```dart theme={null}
// Upload file
final file = File('path/to/file.jpg');
final response = await supabase.storage
  .from('receipts')
  .upload('file.jpg', file);

// Get public URL
final url = supabase.storage
  .from('receipts')
  .getPublicUrl('file.jpg');
```

## Best Practices

1. **Use Row Level Security (RLS)**
2. **Implement proper error handling**
3. **Cache frequently accessed data**
4. **Use database functions for complex queries**
5. **Monitor usage and performance**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.