The session layer for Flutter apps with their own backend.
Your backend issues the tokens. Authyra keeps the session alive on the device: it persists it, refreshes tokens before they expire with a single refresh at a time, survives restarts and network outages, juggles several accounts, and tells your UI what state it is in.
main.dart
final authyra = await Authyra.initialize(
storage: SecureAuthStorage(),
providers: [
CredentialsProvider(
id: 'api',
signIn: (credentials) => api.login(credentials),
refresh: (refreshToken) => api.refresh(refreshToken),
),
],
);
dio.interceptors.add(AuthyraInterceptor(authyra: authyra, dio: dio));
runApp(AuthyraScope(authyra: authyra, child: const App()));
The part of auth every app rewrites, and gets subtly wrong
Signing in is the easy part. The bugs live in what comes after: twenty requests hit a 401 at once and each one refreshes, a rotating refresh token gets used twice and the server logs the user out, the app restarts mid-refresh and loses the new token, a timeout is mistaken for a revoked session. Authyra handles that layer once, with tests for each of these cases.
One refresh at a time
Every caller of a session (the scheduler, your HTTP client,
accessToken()) shares the refresh in flight. Rotating refresh tokens are never used twice.Outages are not sign-outs
Only a refresh token the server rejects ends a session. Timeouts, 5xx and offline periods keep it, with retries and backoff.
Storage before memory
A change becomes visible only once persisted, in the platform keystore. A restart never resurrects a session you signed out of, or loses a rotated token.
Several accounts
Sign in to several accounts on one device, switch between them, send a request on behalf of any of them. Each keeps its own tokens; inactive ones are refreshed when used.
A state your UI can trust
AuthUnknown, AuthSignedIn or AuthSignedOut: a sealed type you can switch over, with widgets for Flutter and a Listenable for your router.Any way to sign in
Your login API, an OAuth 2.0 / OIDC server with PKCE, a social login through your backend, native Google and Apple sign-in, or your own provider.
What Authyra is not
It is not an identity provider and has no server. It does not replace Firebase Auth, Supabase Auth or Auth0: if your app talks only to one of those, its SDK already manages the session. Authyra is for apps whose own API issues the tokens, whichever way the user proves who they are.