AuthState<T> class
sealed
A sealed union representing authentication lifecycle states.
Models all standard auth transitions:
- AuthUnauthenticated — no active user session.
- AuthAuthenticating — login / authentication request in progress.
- AuthAuthenticated — successfully authenticated with user object
user. - AuthError — authentication attempt failed with
errorandstackTrace.
Useful for routing guards (e.g. GoRouter / AutoRoute) and user session management:
final authNode = ZenithNode<AuthState<User>>(const AuthUnauthenticated());
String get initialRoute => authNode.value.when(
authenticated: (user) => '/home',
unauthenticated: () => '/login',
authenticating: () => '/splash',
error: (_, __) => '/login',
);
- Implementers
- Annotations
Properties
- hasError → bool
-
Whether an authentication error has occurred.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isAuthenticated → bool
-
Whether a user is currently authenticated.
no setter
- isAuthenticating → bool
-
Whether an authentication request is in progress.
no setter
- isUnauthenticated → bool
-
Whether the user is currently unauthenticated.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- userOrNull → T?
-
The active user object if authenticated, or
nullotherwise.no setter
Methods
-
maybeWhen<
R> ({R unauthenticated()?, R authenticating()?, R authenticated(T user)?, R error(Object error, StackTrace stackTrace)?, required R orElse()}) → R -
Pattern-matches with an
orElsefallback for unhandled states. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
R> ({required R unauthenticated(), required R authenticating(), required R authenticated(T user), required R error(Object error, StackTrace stackTrace)}) → R - Exhaustively pattern-matches all four auth states.
-
whenOrNull<
R> ({R unauthenticated()?, R authenticating()?, R authenticated(T user)?, R error(Object error, StackTrace stackTrace)?}) → R? -
Pattern-matches and returns
nullfor unhandled states.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited