Skip to main content

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:10
Implementation: backend/SupabaseAuthRepository.kt:15

Interface Definition

Implementation

SupabaseAuthRepository

Features:
  • 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.
Returns: String - The authenticated user’s ID Throws: IllegalStateException - If no user is authenticated Example Usage:

Authentication Flow

While AuthRepository 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:
Implementation:
Verify OTP:
Implementation:

2. Google OAuth

Start OAuth Flow:
Implementation:
OAuth Flow Enum:
Google OAuth uses deep links to return to the app after authentication. Source: AuthActivity.kt:15
Configuration: Deep links must be configured in AndroidManifest.xml to handle the OAuth redirect URL.

Session Management

Session Status Observing

Source: ui/auth/ViewModels/AuthFlowViewModel.kt:51
SessionStatus States:
  • NotAuthenticated - No active session
  • LoadingFromStorage - Checking for saved session
  • Authenticated - Valid session exists
  • NetworkError - Network issue during auth

Retrieving Current User

Source: ui/auth/ViewModels/AuthFlowViewModel.kt:150
When to Use:
  • currentUserOrNull() - Quick check, returns cached user or null
  • retrieveUserForCurrentSession() - 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
Common Errors:
  • 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:
Source: AuthActivity.kt:18

Complete Authentication Flow Example

1. Phone Authentication

2. Google OAuth

See Also