BloomAuth<U> class

Reactive user session manager and persistent authentication layer.

Tracks current user U model, bearer token, and provides computed reactive authentication state signals. Supports optional encrypted persistence via BloomStorageAdapter.

Example:

final auth = BloomAuth<User>(
  storage: BloomSecureStorage(),
  fromJson: User.fromJson,
  toJson: (u) => u.toJson(),
);

await auth.setSession(user: currentUser, token: 'jwt_token');
print(auth.isAuthenticated.value); // true
Implemented types
Implementers

Constructors

BloomAuth({BloomStorageAdapter? storage, U fromJson(Map<String, dynamic> json)?, U userDeserializer(Map<String, dynamic> json)?, Map<String, dynamic> toJson(U user)?, Map<String, dynamic> userSerializer(U user)?, String sessionKey = 'bloom_auth_session', bool autoProvide = false})
Creates a BloomAuth session manager.

Properties

currentUser ReadonlySignal<U?>
Reactive signal containing the currently authenticated user model, or null if unauthenticated.
no setter
fromJson → U Function(Map<String, dynamic> json)?
Deserializer function converting JSON maps to typed user model instances.
final
hashCode int
The hash code for this object.
no setterinherited
isAuthenticated ReadonlySignal<bool>
Reactive boolean signal indicating whether an active authenticated session exists.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sessionKey String
Key identifier used when writing session data into storage (defaults to 'bloom_auth_session').
final
storage BloomStorageAdapter?
Optional persistent storage adapter for caching session state across application restarts.
final
toJson Map<String, dynamic> Function(U user)?
Serializer function converting typed user model instances to JSON maps.
final
token ReadonlySignal<String?>
Reactive signal containing the current authentication bearer token, or null if unauthenticated.
no setteroverride

Methods

login(String token, U user) Future<void>
Logs in the user, setting the active token and user session.
logout() Future<void>
Clears the active user session and purges persistent session storage.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
restoreSession() Future<bool>
Restores user session from persistent storage on application startup.
setSession({required U user, required String token}) Future<void>
Sets the active user user and token session, and persists it to storage if configured.
toString() String
A string representation of this object.
inherited

Operators

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