What is Supabase? Supabase is a service that provides a database (a place to store your app’s data), user authentication (login/signup systems), and other backend features—all without you needing to set up your own servers.
Overview
The Supabase integration in CodinIT offers powerful database capabilities with easy-to-use tools:PostgreSQL Database
A hosted database to store all your app’s information (users, posts, orders, etc.)
Authentication
Ready-made login systems including “Sign in with Google” and email/password
Real-time
Your app updates instantly when data changes—no page refresh needed
Key features
- Automated migrations: Database changes are tracked and can be undone if something goes wrong
- Row Level Security (RLS): Rules that control who can see or edit specific data (for example, users can only see their own orders)
- TypeScript integration: Your code editor knows exactly what data types to expect, reducing errors
- Real-time subscriptions: Your app automatically updates when data changes—like seeing new messages appear without refreshing
- Authentication flows: Complete user registration, login, and session management
- Edge functions: Small programs that run on Supabase’s servers to handle tasks like sending emails or processing payments
- File storage: Built-in file upload and management for images, documents, and other files
Default choice: Supabase is the recommended database solution for CodinIT projects requiring advanced database
features, authentication, or real-time capabilities.
Setup and configuration
Connecting to Supabase
1
Create Supabase Account
Visit Supabase and create a free account
2
Create New Project
Click “New Project” and fill in your project details
3
Get Connection Details
Navigate to Settings > API to get your project URL and API keys
4
Configure in CodinIT
Use the Supabase connection prompt in chat: “Connect to Supabase in the chat box”
5
Provide Credentials
Share your Supabase URL and anon key when prompted
Environment variables
What are environment variables? These are secret settings stored outside your code. They keep sensitive information like passwords and API keys safe, and let you use different settings for testing vs. your live app.
Security note: Never share or publish your Supabase service role key. The “anon key” is safe to use in your app’s front-end code.
Connection verification
Once connected, CodinIT will:- ✅ Confirm successful connection
- ✅ Set up environment variables
- ✅ Prepare for database operations
- Verify your API keys
- Check project permissions
- Ensure network connectivity
Database operations
Creating tables and schemas
What is a table? A table is like a spreadsheet in your database. Each table stores one type of information (like “users” or “orders”), with rows for each item and columns for each piece of data (like “name” or “email”).
Row Level Security (RLS)
What is Row Level Security? RLS is like a security guard for your data. It automatically filters what each user can see or change. For example, you can set rules so users only see their own orders, not everyone else’s.
Data operations
Querying data (getting information from your database):Authentication System
User Registration and Login
CodinIT implements complete authentication flows using Supabase Auth: Supported Authentication Methods:- Email and password registration
- Social provider login (Google, GitHub, etc.)
- Magic link authentication
- Password reset functionality
Session Management
Automatic Session Handling:- JWT token management
- Automatic token refresh
- Session persistence across page reloads
- Secure logout functionality
User Profile Management
Profile Data:- User metadata storage
- Avatar management
- Custom user fields
- Profile update functionality
Email Confirmation: By default, email confirmation is disabled for easier development. Enable it in production for
security.
TypeScript Integration
Auto-Generated Types
CodinIT generates TypeScript types from your Supabase schema: Type Generation:Type-Safe Queries
Full Type Safety:Advanced Features
Real-Time Subscriptions
Live Data Updates:File Storage
File Upload and Management:Edge Functions
Serverless API Endpoints:Best Practices
Database Design
Schema Best Practices:- Use UUID primary keys with
gen_random_uuid() - Enable RLS on all tables
- Create appropriate indexes for query performance
- Use foreign key constraints for data integrity
- One logical change per migration
- Include descriptive comments in SQL
- Test migrations on development data
- Plan rollback strategies
Security Considerations
RLS Policies:- Always enable RLS on user-facing tables
- Create policies for each operation type (SELECT, INSERT, UPDATE, DELETE)
- Test policies with different user roles
- Avoid overly permissive policies
- Use HTTPS for all authentication flows
- Implement proper session management
- Validate user input on both client and server
- Regularly rotate API keys
Troubleshooting
Connection Issues
Connection Issues
Database Connection Problems
Common Issues:- Verify API keys are correct and have proper permissions
- Check that the Supabase project is active and not paused
- Ensure network connectivity to Supabase servers
- Confirm environment variables are properly set
- Regenerate API keys in Supabase dashboard
- Check Supabase project status and billing
- Verify firewall settings allow Supabase connections
- Test connection with a simple query
Migration Errors
Migration Errors
Database Migration Failures
Common Issues:- SQL syntax errors in migration files
- Foreign key constraint violations
- RLS policy conflicts
- Insufficient permissions
- Validate SQL syntax before applying migrations
- Check existing data before adding constraints
- Review RLS policies for conflicts
- Use Supabase dashboard for manual testing
Authentication Problems
Authentication Problems
Auth Flow Issues
Common Issues:- Email confirmation settings
- Social provider configuration
- JWT token expiration
- Password policy conflicts
- Check email confirmation settings in Supabase
- Verify social provider API keys
- Implement proper token refresh logic
- Review password requirements
Performance Issues
Performance Issues
Query Performance Problems
Common Issues:- Missing database indexes
- Inefficient query patterns
- Large result sets
- Real-time subscription overhead
- Add appropriate indexes for query patterns
- Optimize query structure and filtering
- Implement pagination for large datasets
- Limit real-time subscriptions to necessary data
Migration Examples
From Local Database to Supabase
Migration Process:- Export existing data from local database
- Create Supabase tables with proper schemas
- Import data using Supabase client or SQL
- Update application to use Supabase URLs
- Test all functionality with migrated data
Schema Evolution
Safe Schema Changes:Data Safety: Always backup data before making schema changes. Test migrations on development data first.
Development Workflow: Use Supabase’s dashboard for quick testing and data exploration during development.
