Overview
Trazea uses Supabase as its backend platform, providing:- PostgreSQL database with 17 tables for inventory, solicitudes, guarantees, and more
- Authentication with email/password and Google OAuth
- Row Level Security (RLS) for multi-tenant access control
- Storage for warranty photos and spare part images
- Real-time subscriptions for notifications
Prerequisites
- Supabase account (free tier available)
- New Supabase project created
- Project URL and anon key from project settings
Project Setup
1. Create Supabase Project
Create New Project
Go to Supabase Dashboard and click New Project
Configure Project
- Name: Trazea (or your preferred name)
- Database Password: Generate a strong password (save this securely)
- Region: Choose closest to your users
- Pricing Plan: Free tier is sufficient for development
2. Configure Environment Variables
Add these credentials to your.env file:
.env
Authentication Configuration
Trazea supports two authentication methods:Email/Password Authentication
Enabled by default in Supabase. Configuration:Configure Email Settings
- Confirm email: Recommended for production
- Secure email change: Enabled (requires confirmation)
- Secure password change: Enabled
Google OAuth
Trazea supports Google OAuth for single sign-on:Create Google OAuth App
- Go to Google Cloud Console
- Create new project or select existing
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth 2.0 Client ID
- Configure OAuth consent screen if prompted
Configure OAuth Client
- Application type: Web application
- Name: Trazea
- Authorized redirect URIs:
https://your-project.supabase.co/auth/v1/callback
Users who sign in with Google OAuth will have their email automatically verified.
User Registration Flow
Trazea implements an approval-based registration system:- User registers via email/password or Google OAuth
- User profile created in
usuariostable withaprobado = false - Admin receives notification via
admin_notificationstable - Admin approves/rejects user in the admin panel
- User gains access once approved
User Profile Schema
Theusuarios table stores user profiles with these key fields:
User approval status. Must be set to
true by an admin before user can access the system.Admin user who approved/rejected the registration.
Reason for rejection (if applicable).
Row Level Security (RLS)
RLS is critical for Trazea’s multi-tenant security model. It ensures users can only access data for their assigned locations.Enable RLS on All Tables
For each table in your database:Example RLS Policies
Here are example policies for key tables:RLS Policy Patterns
Common patterns used across Trazea:Location-Based Access
Location-Based Access
Most tables filter by
usuarios_localizacion to ensure users only see data for their assigned locations:Permission-Based Access
Permission-Based Access
Actions check role permissions stored in the
permisos JSON field:Owner-Based Access
Owner-Based Access
Some tables allow users to access their own records:
Admin Override
Admin Override
Admin users often bypass restrictions:
Database Schema
Trazea uses 17 primary tables organized into these domains:Core Tables
| Table | Purpose |
|---|---|
usuarios | User profiles, approval status, roles |
roles | Role definitions with JSON permissions |
usuarios_localizacion | User-to-location assignments (many-to-many) |
localizacion | Physical locations/warehouses |
admin_notifications | Admin alert subscriptions |
Inventory Domain
| Table | Purpose |
|---|---|
repuestos | Spare parts catalog (reference, name, type, brand) |
inventario | Stock quantities by location |
logs_inventario | Audit trail for all inventory changes |
movimientos_tecnicos | Technician spare part movements (load/unload) |
Solicitudes (Requests) Domain
| Table | Purpose |
|---|---|
carrito_solicitudes | Shopping cart for multi-item requests |
solicitudes | Transfer requests between locations |
detalles_solicitudes | Line items with quantities requested/dispatched/received |
trazabilidad_solicitudes | Complete audit trail of status changes |
Guarantees Domain
| Table | Purpose |
|---|---|
garantias | Warranty claims with photos, km, failure reasons |
Audit/Counting Domain
| Table | Purpose |
|---|---|
registro_conteo | Physical inventory count sessions |
detalles_conteo | Count details (system qty vs physical qty) |
Orders Domain
| Table | Purpose |
|---|---|
scooter_types | Catalog of scooter models |
order_follow | Customer order tracking (levels 1-3) |
For the complete schema with all columns and relationships, see the Database Model.
Storage Configuration
Trazea uses Supabase Storage for images:Create Storage Buckets
Create Buckets
Create these buckets:
repuestos-images: Spare part photosgarantias-images: Warranty claim evidence photosavatares: User profile pictures (optional)
CORS Configuration
Configure CORS to allow requests from your frontend domain:Real-Time Subscriptions
Trazea uses real-time subscriptions for notifications. Enable for these tables:Production Checklist
Authentication
✓ Email confirmation enabled for production✓ Google OAuth configured with correct redirect URIs✓ Email templates customized
Row Level Security
✓ RLS enabled on ALL tables✓ Policies tested for each user role✓ Admin users cannot bypass RLS without explicit policy
Storage
✓ Storage buckets created✓ Bucket policies configured✓ File size limits set (10 MB recommended)
CORS & Security
✓ CORS configured with exact domains (no wildcards)✓ Database password strong and stored securely✓ API keys rotated if exposed
Migration and Backups
Database Migrations
For schema changes, use Supabase CLI:Automated Backups
Supabase Pro and Team plans include:- Daily automated backups (retained for 7 days)
- Point-in-time recovery (PITR) for accidental data loss
- Export database regularly: Database > Backups > Export
- Store exports securely offsite
Troubleshooting
Authentication Not Working
Authentication Not Working
- Verify environment variables are correct
- Check that Supabase URL includes
https://protocol - Ensure email provider is enabled in Supabase Auth settings
- For Google OAuth, verify redirect URI matches exactly
RLS Policy Errors
RLS Policy Errors
If users see “permission denied” errors:
- Check policy syntax in Database > Policies
- Test query in SQL Editor as that user:
SET LOCAL ROLE authenticated; SET LOCAL request.jwt.claim.sub = 'user-uuid'; - Verify
usuarios_localizacionassignments are correct - Ensure user has
aprobado = trueinusuariostable
CORS Errors
CORS Errors
If seeing “CORS policy blocked” errors:
- Add your frontend domain to Settings > API > CORS
- Ensure protocol matches (http vs https)
- Remove trailing slashes from origins
- Wait ~1 minute for CORS changes to propagate
Storage Upload Failures
Storage Upload Failures
- Check bucket exists and is public/private as intended
- Verify storage policies allow the operation
- Ensure file size is under limit (default 50 MB)
- Check file type is allowed (configure in bucket settings)
Next Steps
Environment Setup
Configure environment variables for local and production
Deploy to Vercel
Deploy your Trazea instance to Vercel