AuthState<T> class sealed

A sealed union representing authentication lifecycle states.

Models all standard auth transitions:

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 null otherwise.
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 orElse fallback 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 null for unhandled states.

Operators

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