Sign-out and revocation
Signing out
await authyra.signOut();
In order:
- New refreshes of the session are blocked.
- A refresh already in flight is awaited, up to 10 seconds, so the newest tokens are the ones revoked.
- The provider's
signOutrevokes the session server-side. If that call fails (offline, server error), the failure is logged and the sign-out continues. - The session is removed from storage, then from memory.
SessionEndedEvent(reason: signedOut)is emitted, and the state changes.
If the same user signs in again while step 3 is still running, the new session is kept: the late sign-out does not remove it.
signOut never asks your AuthPolicy: a user can always sign out.
When the server ends the session
A session ends without the user asking when its refresh token is rejected: revoked by an admin, a password change, reuse detection, or simply expired. Authyra emits SessionEndedEvent(reason: revoked) and the state moves to the next account or to AuthSignedOut.
Tell the user why:
authyra.events.listen((event) {
if (event case SessionEndedEvent(reason: SessionEndReason.revoked)) {
showBanner('You were signed out. Please sign in again.');
}
});
A session also ends with SessionEndReason.expired when it can no longer be renewed: its access token expired and it has no usable refresh token. This is detected at startup, on a scheduled check, on accessToken() or on switchTo.
Revoking on your backend
Implement the provider's sign-out so a stolen refresh token stops working:
CredentialsProvider(
id: 'api',
signIn: loginWithApi,
refresh: refreshWithApi,
signOut: (session) async {
final refreshToken = session.tokens?.refreshToken;
if (refreshToken != null) {
await authApi.post<void>('/auth/sign-out', data: {'refresh_token': refreshToken});
}
},
)
OAuth2Provider calls the server's revocation endpoint when revocationEndpoint is set; BackendOAuthProvider posts to signOutEndpoint.
Wiping everything
await authyra.signOutAll(); // At runtime: revokes and removes every session.
await const SecureAuthStorage().deleteAll(); // Before start(): removes Authyra's keys only.