Supabase is an open-source Firebase alternative that provides PostgreSQL database, authentication, real-time subscriptions, and storage. This guide walks you through integrating Supabase into your Emergent application.
Supabase is perfect when you need a powerful relational database with real-time capabilities and built-in authentication.
I need to integrate Supabase PostgreSQL database:Purpose: Replace MongoDB with PostgreSQL for [your use case]Supabase Credentials:- Project URL: https://xxxxx.supabase.co- Anon Key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...- Service Role Key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Database Tables Needed:- users: id (uuid), email (text), name (text), created_at (timestamp)- posts: id (uuid), user_id (uuid), title (text), content (text), created_at (timestamp)- comments: id (uuid), post_id (uuid), user_id (uuid), content (text), created_at (timestamp)Features Required:- CRUD operations for all tables- Backend API endpoints- Frontend client for data fetching- Foreign key relationshipsTechnical Setup:- Backend: Supabase Python client for API endpoints- Frontend: Supabase JS client for direct queries- Create SQL migration script for tablesPlease call integration_playbook_expert for Supabase setup.
I need Supabase with database and authentication:Purpose: PostgreSQL database + Google social loginSupabase Credentials:- Project URL: https://xxxxx.supabase.co- Anon Key: eyJhbGci...- Service Role Key: eyJhbGci...Database Tables:[List your tables]Authentication:- Google social login- Email/password signup- Protected routes- User session managementSetup:- Backend: API with Supabase auth- Frontend: Login UI + auth context- Database: User profiles tablePlease call integration_playbook_expert.
I need Supabase with real-time subscriptions:Purpose: Chat app with real-time message updatesSupabase Credentials:- Project URL: https://xxxxx.supabase.co- Anon Key: eyJhbGci...- Service Role Key: eyJhbGci...Real-Time Features:- Subscribe to new messages- Live updates without refresh- Typing indicators- Online presenceDatabase Tables:- messages: id, room_id, user_id, content, created_at- rooms: id, name, created_atSetup:- Backend: Message API endpoints- Frontend: Real-time subscription to messages tablePlease call integration_playbook_expert.
-- Create users tableCREATE TABLE users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), name TEXT NOT NULL, email TEXT UNIQUE NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW());-- Create posts tableCREATE TABLE posts ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES users(id) ON DELETE CASCADE, title TEXT NOT NULL, content TEXT, created_at TIMESTAMPTZ DEFAULT NOW());-- Create comments tableCREATE TABLE comments ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), post_id UUID REFERENCES posts(id) ON DELETE CASCADE, user_id UUID REFERENCES users(id) ON DELETE CASCADE, content TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW());-- Create indexes for better performanceCREATE INDEX idx_posts_user_id ON posts(user_id);CREATE INDEX idx_comments_post_id ON comments(post_id);CREATE INDEX idx_comments_user_id ON comments(user_id);
Can you create SQL migration for Supabase with these tables:**users table:**- id (uuid, primary key)- email (text, unique)- name (text)- avatar_url (text, nullable)- created_at (timestamp)**posts table:**- id (uuid, primary key)- user_id (uuid, foreign key to users)- title (text)- content (text)- published (boolean, default false)- created_at (timestamp)**tags table:**- id (uuid, primary key)- name (text, unique)**post_tags table (many-to-many):**- post_id (uuid, foreign key to posts)- tag_id (uuid, foreign key to tags)- primary key (post_id, tag_id)Include indexes for foreign keys and commonly queried fields.
-- Policy: Users can read their own postsCREATE POLICY "Users can view own posts" ON posts FOR SELECT USING (auth.uid() = user_id);-- Policy: Users can insert their own postsCREATE POLICY "Users can create posts" ON posts FOR INSERT WITH CHECK (auth.uid() = user_id);-- Policy: Users can update their own postsCREATE POLICY "Users can update own posts" ON posts FOR UPDATE USING (auth.uid() = user_id);-- Policy: Users can delete their own postsCREATE POLICY "Users can delete own posts" ON posts FOR DELETE USING (auth.uid() = user_id);
Example: Public read, authenticated write
-- Anyone can read postsCREATE POLICY "Public posts are visible" ON posts FOR SELECT USING (published = true);-- Authenticated users can create postsCREATE POLICY "Authenticated users can create posts" ON posts FOR INSERT TO authenticated WITH CHECK (true);
I need Supabase for a blog platform:**Tables:**- users: author profiles- posts: blog posts with rich content- comments: reader comments- tags: post categorization**Features:**- CRUD for posts- Real-time comments- User authentication- Post search and filteringSupabase credentials: [will provide]Please call integration_playbook_expert.
Supabase connection failing with error:[paste error]Can you verify the Supabase client configuration?
RLS Blocking Queries
Error: “Row level security policy” or empty resultsSolutions:
Check if RLS is enabled
Verify policies allow the operation
Use service role key in backend (bypasses RLS)
Test with RLS disabled temporarily
Ask agent:
Supabase queries returning empty due to RLS.Can you:1. Check RLS policies2. Update policies to allow [operation]3. Or guide me to disable RLS for testing
Real-Time Not Working
Error: Subscriptions not receiving updatesSolutions:
Verify Real-time is enabled for table
Check subscription code is correct
Ensure listening for correct events
Check browser console for errors
Ask agent:
Real-time subscriptions not working for [table].Updates in database but not appearing in UI.Can you debug the real-time subscription code?