Overview
AuthRepository handles user authentication and session management. It provides a simple interface for getting the current user ID, with the actual authentication flow managed by Supabase Auth.
Interface: backend/AuthRepository.kt:10Implementation:
backend/SupabaseAuthRepository.kt:15
Interface Definition
Implementation
SupabaseAuthRepository
- Returns current authenticated user ID
- Supports development bypass mode
- Throws error if no user is authenticated
Methods
getCurrentUserId
Returns the ID of the currently authenticated user.String - The authenticated user’s ID
Throws: IllegalStateException - If no user is authenticated
Example Usage:
Authentication Flow
WhileAuthRepository only exposes getCurrentUserId(), the actual authentication is handled by AuthFlowViewModel and Supabase Auth.
Supported Authentication Methods
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:42
1. Phone Authentication (OTP)
Send OTP:2. Google OAuth
Start OAuth Flow:Deep Link Handling
Google OAuth uses deep links to return to the app after authentication. Source:AuthActivity.kt:15
AndroidManifest.xml to handle the OAuth redirect URL.
Session Management
Session Status Observing
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:51
NotAuthenticated- No active sessionLoadingFromStorage- Checking for saved sessionAuthenticated- Valid session existsNetworkError- Network issue during auth
Retrieving Current User
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:150
currentUserOrNull()- Quick check, returns cached user or nullretrieveUserForCurrentSession()- Fetches from server and updates session
User Profile Creation
After authentication, users must create a profile with their details. Source:ui/auth/ViewModels/AuthFlowViewModel.kt:135
Checking Profile Existence
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:196
Auth State Management
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:26
State Updates
Error Handling
Source:ui/auth/ViewModels/AuthFlowViewModel.kt:219
- Invalid or expired OTP code
- Missing Supabase configuration
- Network connectivity issues
- Phone number format errors
- Missing required profile fields
Development Mode
The repository supports an auth bypass for development:AuthActivity.kt:18