Overview
The Supabase client is configured differently for mobile (React Native) and web (Next.js) platforms to handle authentication and session management appropriately for each environment.Mobile Client (React Native)
The mobile client uses Expo SecureStore for secure session persistence.Configuration
Supabase project URL from
EXPO_PUBLIC_SUPABASE_URL environment variableSupabase anonymous key from
EXPO_PUBLIC_SUPABASE_ANON_KEY environment variableCustom storage adapter using Expo SecureStore for secure token persistence
Enables session persistence across app restarts
Automatically refreshes authentication tokens before expiration
Disabled for mobile as sessions are not passed via URLs
Code Example
mobile/src/services/supabase.ts
Usage
Web Client (Next.js)
Browser Client
For client-side operations in Next.js, use the browser client.Supabase project URL from
NEXT_PUBLIC_SUPABASE_URL environment variableSupabase anonymous key from
NEXT_PUBLIC_SUPABASE_ANON_KEY environment variableweb/lib/supabase.ts
Server Client
For server-side operations, use the server client with cookie-based authentication.Cookie configuration for server-side session management
Function to retrieve cookie values from Next.js cookie store
Placeholder function for setting cookies (handled by Next.js)
Placeholder function for removing cookies (handled by Next.js)
web/lib/supabase-server.ts
Usage
Environment Variables
Mobile (React Native)
.env
Web (Next.js)
.env.local
Security
- Mobile: Sessions are stored securely in Expo SecureStore (encrypted storage)
- Web Browser: Sessions are stored in cookies with automatic CSRF protection
- Web Server: Sessions are read from cookies server-side for authentication
- Both platforms use the anonymous key for client-side operations with Row Level Security (RLS)