© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•2mo ago•
3 replies
anna5180

Authentication persistence issues when upgrading Supabase Flutter from v1 to v2

🔵Flutterauth
I want to ensure that users only need to log in the first time after downloading my mobile app, and save their user sessions so they don't need to re-authenticate every single time they open the app.

Previously on v1.10.0 of the
supabase_flutter
supabase_flutter
package (https://pub.dev/packages/supabase_flutter) I was able to make my authentication persist by storing the sessionString and recovering it when necessary with recoverSession:
String? sessionString = locator<SupabaseClient>().auth.currentSession?.persistSessionString;

await locator<SharedPreferences>().setString(
  supabaseSessionKey,
  sessionString,
);

await locator<SupabaseClient>().auth.recoverSession(sessionString);
String? sessionString = locator<SupabaseClient>().auth.currentSession?.persistSessionString;

await locator<SharedPreferences>().setString(
  supabaseSessionKey,
  sessionString,
);

await locator<SupabaseClient>().auth.recoverSession(sessionString);

Now that I have upgraded my Flutter and Supabase versions to the latest stable (v2),
persistSessionString
persistSessionString
is deprecated and I'm struggling to figure out how to get my authentication tokens to persist.

I've seen in the docs (https://supabase.com/docs/reference/dart/upgrade-guide) you can check if a session is expired with

Session? currentSession = locator<SupabaseClient>().auth.currentSession;
final isSessionExpired = session?.isExpired;
Session? currentSession = locator<SupabaseClient>().auth.currentSession;
final isSessionExpired = session?.isExpired;

but it seems like there isn't/ I shouldn't need to cache my session in v2. When I close and reopen the app I do not have an auth token anymore.

I am initializing in main as so:
await Supabase.initialize(
  url: supabaseUrl,
  anonKey: supabaseKey,
);
await Supabase.initialize(
  url: supabaseUrl,
  anonKey: supabaseKey,
);

Any help much appreciated, thanks!
Dart packages
supabase_flutter | Flutter package
Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
supabase_flutter | Flutter package
Flutter: Upgrade guide | Supabase Docs
Supabase API reference for Flutter: Upgrade guide
Flutter: Upgrade guide | Supabase Docs
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Upgrading supabase into v2 subscribe
SupabaseSSupabase / help-and-questions
4y ago
I'm having CORS issues when upgrading functions to use Supabase v2.0.0
SupabaseSSupabase / help-and-questions
4y ago
Supabase MCP server authentication issues
SupabaseSSupabase / help-and-questions
3mo ago
Has anyone migrated a medium sized codebase from supabase v1 to v2 with Typescript?
SupabaseSSupabase / help-and-questions
4y ago