AuthManager<TProfileModel extends TetherModel<TProfileModel> > constructor
AuthManager<TProfileModel extends TetherModel<TProfileModel> > ({
- required SupabaseClient supabaseClient,
- required SqliteConnection localDb,
- required String supabaseProfileTableName,
- required String localProfileTableName,
- required FromJsonFactory<
TProfileModel> profileFromJsonFactory, - required Map<
String, SupabaseTableInfo> tableSchemas,
Creates an instance of AuthManager.
Parameters:
supabaseClient
: TheSupabaseClient
instance for backend communication.localDb
: TheSqliteConnection
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 ofTProfileModel
.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);
}