Prerequisites
- A Supabase account (sign up at supabase.com)
- Supabase CLI installed (optional, for local development)
- Basic understanding of PostgreSQL and SQL
Create a Supabase Project
Sign in to Supabase
Go to app.supabase.com and sign in with your account.
Create New Project
Click New Project and provide:
- Project Name:
transport-logistics(or your preferred name) - Database Password: A strong, secure password (save this securely)
- Region: Choose the region closest to your users
- Pricing Plan: Select Free tier for development or Pro for production
Wait for Provisioning
Supabase will provision your project. This typically takes 1-2 minutes. Once ready, you’ll see your project dashboard.
Database Schema Setup
The Transport Logistics application uses the following main tables:profiles- User profiles with role-based accessvehicles- Fleet vehicle informationshipments- Shipment tracking datapackages- Package detailsmaterials- Material inventoryroutes- Delivery routestransporters- Transporter informationuser_settings- User preferences
Running Migrations
You have two options for setting up your database schema:- Via Dashboard (Recommended)
- Via Supabase CLI
Create Tables and Functions
Copy and execute your migration files in order. The application includes:
- Initial Schema: Create all tables, relationships, and functions
- RLS Policies: Enable Row Level Security (see next section)
- Unique Constraints: Add data integrity rules
Row Level Security (RLS) Configuration
Row Level Security ensures users can only access data they’re authorized to see. The application implements role-based access control.Understanding RLS Policies
The application uses three main user roles:- Admin: Full access to all resources
- Manager: Can view and manage assigned resources
- User: Limited access to assigned packages and shipments
Enable RLS on Tables
Enable RLS
For each table (
vehicles, shipments, packages, materials, profiles, user_settings, routes, transporters):- Click on the table name
- Go to the Policies tab
- Click Enable RLS if not already enabled
Key RLS Policies
Vehicles, Shipments, Routes, Materials, Transporters
Vehicles, Shipments, Routes, Materials, Transporters
- View: All authenticated users
- Manage: Admin users only
Packages
Packages
- View: Admin users, package creators, or assigned users
- Manage: Admin users and package creators
Profiles
Profiles
- View: Users can view their own profile; admins can view all
- Update: Users can update their own profile; admins can manage all
User Settings
User Settings
- All Operations: Users can only access their own settings
Helper Function
The application uses a security definer function to check user roles:Authentication Configuration
Enable Auth Providers
Navigate to Authentication > Providers:
- Email: Enabled by default (recommended)
- Magic Link: Optional, for passwordless authentication
- OAuth Providers: Configure Google, GitHub, etc. (optional)
Configure Email Templates
Go to Authentication > Email Templates and customize:
- Confirm Signup: Welcome email with verification link
- Magic Link: Passwordless login email
- Change Email Address: Email change confirmation
- Reset Password: Password reset link
Update templates with your brand name and customize messaging for better user experience.
Set URL Configuration
Go to Authentication > URL Configuration:
- Site URL: Your application URL (e.g.,
https://your-domain.com) - Redirect URLs: Add allowed callback URLs:
http://localhost:8080/**(for local development)https://your-domain.com/**(for production)https://preview-*.vercel.app/**(for preview deployments)
Edge Functions (Optional)
The application includes Edge Functions for server-side operations:Available Functions
- create-user: Server-side user creation with JWT verification
- change-user-password: Password management with authentication
- delete_user: User deletion with cleanup
- get_user_email: Retrieve user email by ID
Deploying Edge Functions
Getting API Keys
Copy Keys
You’ll need two keys for your application:For Client-Side (Application):For Server-Side/Admin Operations (keep secret):
Connecting to Production Database
For direct database access (migrations, backups, etc.):Database Backups
Supabase automatically backs up your database:- Free Tier: Daily backups, 7-day retention
- Pro Tier: Daily backups, 30-day retention, point-in-time recovery
Manual Backup
Security Best Practices
Use RLS Policies
Always enable Row Level Security on all tables. Never disable RLS in production.
Rotate Keys Regularly
Regenerate API keys periodically and after any suspected security breach.
Monitor Logs
Review authentication logs and API usage regularly in the Supabase dashboard.
Limit Permissions
Grant minimum required permissions. Use service role key only server-side.
Monitoring and Performance
Enable Monitoring
View Database Usage
Navigate to Settings > Usage to monitor:
- Database size
- API requests
- Bandwidth usage
- Authentication users
Check Database Performance
Go to Database > Performance to:
- Identify slow queries
- View index usage
- Monitor connection pool
Optimize Performance
- Add Indexes: Create indexes on frequently queried columns
- Use Connection Pooling: Enable Supavisor for connection management
- Optimize Queries: Use the SQL Editor to analyze and optimize slow queries
- Enable Caching: Use Supabase’s built-in caching for read-heavy operations
Troubleshooting
Connection Errors
- Verify API keys are correct and not expired
- Check if IP is allowed (Supabase allows all IPs by default)
- Ensure network/firewall isn’t blocking requests
RLS Policy Errors
- Check user has correct role in
profilestable - Verify RLS policies are created and enabled
- Test policies using the SQL Editor with different user contexts
Migration Failures
- Run migrations in order (check timestamps in filenames)
- Verify no conflicting table/column names
- Check PostgreSQL logs in Supabase dashboard
Authentication Issues
- Verify redirect URLs are configured correctly
- Check email templates are set up
- Ensure SMTP settings are correct (if using custom email)
Next Steps
Deployment Guide
Deploy your application to production
Database Schema
Explore the database tables and relationships