Changes:
1. Created migration 004_create_upsert_function.sql:
- Creates upsert_user_profile() function with SECURITY DEFINER
- Bypasses RLS to allow profile creation/updates
- Only accessible to authenticated users via auth.uid()
2. Updated ProfileSettings.tsx:
- Changed from direct upsert to RPC function call
- Updated updateProfile() to use supabase.rpc()
- Updated updateNotificationSettings() to use same function
This solves the RLS policy violation by using a secure
server-side function that properly handles authentication.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Updated migration 003 to properly handle RLS:
- Make username nullable with default
- Drop all existing policies and recreate them
- Add proper INSERT policy with WITH CHECK clause
- Add UPDATE policy with both USING and WITH CHECK
This fixes RLS error blocking profile creation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Changes:
1. Created migration 003_fix_profile_creation.sql:
- Added INSERT policy for profiles table
- Made username nullable with default value
- Created upsert_profile function for safe upserts
2. Updated ProfileSettings.tsx:
- Changed from .update() to .upsert()
- Added id field to upsert data
- Added loadProfile() call after save to refresh state
This fixes the issue where users couldn't update their profile
because no profile row existed in the database.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Update VITE_SUPABASE_URL to correct API endpoint
- Update .env.example with correct Supabase project URL
- Add comprehensive database migration script (001_initial_schema.sql)
- Create profiles, admin_roles, wallets, and referral_history tables
- Implement Row Level Security (RLS) on all tables
- Add auto-generation of referral codes
- Add detailed Supabase setup guide (README.md)
This fixes the sign up issue by:
1. Correcting invalid Supabase credentials format
2. Providing SQL schema for required database tables
3. Setting up proper RLS policies for data security
To complete setup:
1. Run supabase/migrations/001_initial_schema.sql in Supabase SQL Editor
2. Add real VITE_SUPABASE_ANON_KEY to .env file
3. Test sign up functionality
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>