AuthManager<TProfileModel extends TetherModel<TProfileModel>> constructor

AuthManager<TProfileModel extends TetherModel<TProfileModel>>({
  1. required SupabaseClient supabaseClient,
  2. required SqliteConnection localDb,
  3. required String supabaseProfileTableName,
  4. required String localProfileTableName,
  5. required FromJsonFactory<TProfileModel> profileFromJsonFactory,
  6. required Map<String, SupabaseTableInfo> tableSchemas,
})

Creates an instance of AuthManager.

Parameters:

  • supabaseClient: The SupabaseClient instance for backend communication.
  • localDb: The SqliteConnection for local data persistence.
  • supabaseProfileTableName: The name of the table in Supabase that stores user profiles.
  • localProfileTableName: The name of the table in the local SQLite database to store the user profile.
  • profileFromJsonFactory: A function that can convert a JSON map into an instance of TProfileModel.
  • tableSchemas: A map containing schema information for tables, used to correctly interact with the local database, particularly for upserting the profile. The key should be in the format 'schema.table_name' (e.g., 'public.profiles').

Implementation

AuthManager({
  required SupabaseClient supabaseClient,
  required SqliteConnection localDb,
  required String supabaseProfileTableName,
  required String localProfileTableName,
  required FromJsonFactory<TProfileModel> profileFromJsonFactory,
  required Map<String, SupabaseTableInfo> tableSchemas,
}) : _supabaseClient = supabaseClient,
     _localDb = localDb,
     _supabaseProfileTableName = supabaseProfileTableName,
     _localProfileTableName = localProfileTableName,
     _profileFromJsonFactory = profileFromJsonFactory,
     _tableSchemas = tableSchemas {
  _authSubscription = _supabaseClient.auth.onAuthStateChange.listen(
    _onAuthStateChanged,
  );
  // Initialize with current state
  final currentSession = _supabaseClient.auth.currentSession;
  final initialAuthState =
      currentSession == null
          ? AuthState(AuthChangeEvent.signedOut, null)
          : AuthState(AuthChangeEvent.signedIn, currentSession);
  _onAuthStateChanged(initialAuthState);
}