Complete documentation of authentication flow, database structure, and user management
Version 2 | Last Updated: September 9, 2025
Hypnoelp uses Supabase Authentication for user management, providing secure email/password authentication and comprehensive user session management. The system includes email verification, password reset functionality, and seamless offline support.
Traditional authentication with email confirmation requirement
Works on Android, with Web (future) and iOS (future) support
Cached profiles for offline access
| Table Name | Purpose | Key Fields |
|---|---|---|
| auth.users | Supabase built-in authentication table | id, email, encrypted_password, email_confirmed_at, user_metadata |
| public.user_profile | Application user profiles with comprehensive data | user_id (FK to auth.users), first_name, last_name, email, phone_number, country, created_at, updated_at, lead_source |
| public.app_logs | Application logging for signup tracking | id, user_id, log_type, message, origin, created_at, updated_at |
| Function Name | Purpose | Input | Action |
|---|---|---|---|
| delete-unlinked-user | Clean up auth users without user_profile records | email address | Deletes orphaned auth.users record using admin privileges |
| Stage | Log Message | Action |
|---|---|---|
| Initial Signup | "Waiting for email confirmation" | INSERT new log entry |
| Email Confirmed | "Email confirmed and account created successfully" | UPDATE existing log entry |
| Profile Creation Failed | "Failed to create user profile: [error details]" | UPDATE existing log entry |
| Scenario | User Experience | Backend Process |
|---|---|---|
| Valid Credentials | Immediate login and redirect to home | Auth token created, user profile loaded |
| Invalid Email | Error: "Please enter a valid email" | Validation fails client-side |
| Wrong Password | Error: "Invalid login credentials" | Supabase auth rejection |
| Unconfirmed Email | Error: "Email not confirmed" | Auth blocked until confirmation |
| No Internet | Uses cached profile if available | Offline mode activated |
| Unlinked Auth User | Signup appears to fail initially | Automatic cleanup โ fresh signup succeeds |
| Unlinked User Profile | Signup succeeds normally | Self-healing: updates existing profile with new auth ID |
| Error Type | User Message | Resolution |
|---|---|---|
| Network Error | "Unable to connect. Please check your internet connection" | Retry button provided, offline mode activated |
| Duplicate Email | "This email is already registered" | Suggest sign-in instead of sign-up |
| Invalid Credentials | "Invalid login credentials" | Clear password field, show forgot password link |
| Rate Limit | "Too many requests. Please wait X seconds" | Show countdown timer, disable action button |
| Email Not Confirmed | "Please check your email to confirm your account" | Show resend button with cooldown |
| Unlinked Auth Cleanup | Transparent to user (background process) | Edge function deletes auth user, allows fresh signup |
| Edge Function Error | Signup continues normally | Cleanup fails gracefully, doesn't block user flow |
| Email Send Rate Limit | "For security purposes, you can only request this after X seconds" | Cleanup skipped, fresh signup attempted anyway |
| Platform | Deep Link Format | Usage |
|---|---|---|
| Android | io.lucidflow://login-callback | Email confirmation redirect |
| iOS (future) | io.lucidflow://login-callback | Email confirmation redirect |
| Web (future) | https://hypno-56118.web.app/ | Standard web URLs |
| File | Purpose |
|---|---|
lib/screens/login_screen.dart |
Login/Signup UI, form validation, user interaction |
lib/screens/forgot_password_screen.dart |
Password reset UI and flow management |
lib/providers/user_provider.dart |
State management, auth logic, profile caching, email confirmation polling |
lib/services/supabase_service.dart |
Supabase API calls, database operations, unlinked user detection & cleanup |
lib/models/user_profile.dart |
User data model and JSON serialization |
supabase/functions/delete-unlinked-user/index.ts |
Edge function for safely deleting unlinked auth users with admin privileges |
The Hypnoelp authentication system provides a robust, secure, and user-friendly authentication experience with: