Skip to content

Latest commit

 

History

History

example

Folders and files

smart_refresh_token example

A complete Flutter app that uses smart_refresh_token with:

  • SecureTokenStorage (lib/secure_token_storage.dart), built on flutter_secure_storage. Copy it into your app.
  • A StreamBuilder on auth.authStatus that switches between the logged-in and logged-out UI.
  • TokenRefreshLifecycleObserver, which refreshes on app resume.
  • An in-app fake server (lib/fake_server.dart), so it runs offline on Android, iOS, macOS, Windows, Linux and web.
flutter run

Try it:

  1. Log in.
  2. Expire access token (server side), then 10 parallel requests. The log shows 10 succeeded, 1 refresh call(s).
  3. Wait about 20 seconds: the token is refreshed proactively before the next request.
  4. Revoke refresh token, Expire access token, then GET /me. The session ends and the UI switches back to logged out.

To use a real backend, delete fake_server.dart and the httpClientAdapter = server line in main.dart, then point baseUrl at your API.