79500331

Date: 2025-03-11 10:09:05
Score: 3
Natty:
Report link

I tried doing this, but every time I force quit the app and reopen it, the authentication does not persist

class SupabaseService {
  Future initialize() async {
    await Supabase.initialize(
      url: supabaseUrl,
      anonKey: supabaseKey,
    );
  }
}

// register the service
await locator<SupabaseService>().initialize(); 

// .. some code

if (!locator.isRegistered<SupabaseClient>()) {
    locator.registerLazySingleton<SupabaseClient>(
      () => Supabase.instance.client,
    );
}

I had managed to make it persist by using local storage and saving the sessionString and recovering it. But now that I have upgraded my flutter and supabase version, the persistSessionString no longer exists

String? sessionString =
      locator<SupabaseClient>().auth.currentSession?.persistSessionString;
// Add to local storage

// Get session string from local storage and recover session
await locator<SupabaseClient>().auth.recoverSession(sessionString);

Anyone got any ideas?

Reasons:
  • Blacklisted phrase (1): any ideas
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Viv Shen