AuthState class sealed

The current authentication state.

Observe it with BetterAuthFlutter.authStateChanges, or gate your widget tree with BetterAuthBuilder.

AuthInitial and Unauthenticated are deliberately distinct. "We have not looked yet" is not the same as "there is no session": collapsing them makes an app flash its sign-in screen on every cold start while the stored session is still loading.

Annotations
  • @freezed

Constructors

AuthState.authenticated({required User user, Session? session})
There is a valid session.
const
factory
AuthState.error(BetterError error)
The last session lookup failed. The session may still be valid — this usually means the network was unreachable — so treat it as distinct from Unauthenticated rather than signing the user out.
const
factory
AuthState.initial()
No session lookup has completed yet. Show a splash screen.
const
factory
AuthState.loading()
A session lookup is in flight and the outcome is not yet known.
const
factory
AuthState.unauthenticated()
There is no session.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isAuthenticated bool
Whether there is a confirmed session.
no setter
isResolving bool
Whether we are still determining the session (splash-worthy).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
user User?
The signed-in user, or null in every other state.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited