Users were being created in Supabase Auth (auth.users table) but not in your custom users table, causing empty tables in your Supabase dashboard.
- ✅ Updated
createUserProfilefunction to insert records into customuserstable - ✅ Added
ensureUserProfilefunction to create profiles for existing users - ✅ Updated registration flow to call
createUserProfile - ✅ Updated login flow to use
ensureUserProfile - ✅ Updated auth state change handler to ensure profiles exist
- ✅ Created
database/user_trigger.sqlwith automatic triggers - ✅ Triggers automatically create user records when auth.users is updated
- Go to your Supabase Dashboard
- Navigate to SQL Editor
- Copy and paste the contents of
database/user_trigger.sql - Click "Run" to execute the triggers
This will create automatic triggers that ensure every user in auth.users gets a corresponding record in your users table.
-
Restart your development server:
cd frontend npm run dev -
Test registration:
- Go to http://localhost:5173/register
- Create a new account
- Check your Supabase dashboard → Table Editor →
userstable - You should see the new user record
-
Test login:
- Go to http://localhost:5173/login
- Log in with existing credentials
- The system will automatically create a profile if it doesn't exist
-
Check Supabase Dashboard:
- Go to Table Editor
- Select the
userstable - You should see user records with:
id(matches auth.users)emailfull_namemetadata(JSON with first_name, last_name, zip_code)email_verifiedcreated_atandupdated_at
-
Check Browser Console:
- Look for messages like:
- "Successfully created user profile in users table"
- "User profile not found, creating from metadata"
- Look for messages like:
- User signs up → Creates record in
auth.users createUserProfileis called → Creates record in customuserstable- User metadata is stored in both places
- User logs in → Authenticated via
auth.users ensureUserProfilechecks if record exists in customuserstable- If not found, creates it from user metadata
- Profile is fetched and set in the app
- Any time
auth.usersis updated → Trigger fires - Automatically creates/updates record in custom
userstable - Ensures data consistency even if frontend fails
- New Registration: Creates user in both
auth.usersanduserstable - Existing User Login: Creates profile if missing
- Database Triggers: Work as backup (test by creating user directly in Supabase)
- Profile Data: First name, last name, email, zip code are stored correctly
- Email Verification: Status is tracked properly
-
Check Browser Console:
- Look for error messages
- Check if
createUserProfileis being called
-
Check Supabase Logs:
- Go to Logs in your Supabase dashboard
- Look for database errors
-
Verify Database Schema:
- Make sure the
userstable exists - Check that RLS policies allow inserts
- Make sure the
-
Test Database Triggers:
- Create a user manually in Supabase Auth
- Check if trigger creates the profile automatically
-
Check RLS Policies:
- Make sure authenticated users can insert into
userstable - Verify the policies in
database/schema.sqlare applied
- Make sure authenticated users can insert into
-
Check Service Role:
- Ensure your Supabase project has proper permissions
- The triggers use
SECURITY DEFINERto bypass RLS
After applying the fix, you should see:
-
In Supabase Dashboard → Table Editor →
users:id: uuid (matches auth.users.id) email: text full_name: text metadata: jsonb (contains first_name, last_name, zip_code) email_verified: boolean created_at: timestamp updated_at: timestamp -
In Browser Console:
- Success messages when profiles are created
- No error messages during registration/login
-
In Your App:
- Users can register and login successfully
- Profile data is available throughout the app
- Protected routes work properly
✅ Fix is working when:
- New registrations create records in both tables
- Existing users get profiles created on login
- Database triggers work as backup
- No errors in browser console or Supabase logs
- User data is properly stored and accessible
The fix ensures that every user in your Supabase Auth system has a corresponding profile in your custom users table, solving the empty tables issue! 🎉