AuthSession class

Represents an authenticated user session backed by both persistent storage and an in-memory session registry.

An AuthSession stores the authenticated user's email, a session token, the timestamp of the most recent activity, and the request cookie currently associated with the session.

This model is used to:

  • persist session records
  • resolve the current authenticated user from an HTTP request
  • validate session freshness
  • manage login and logout flows

Fields:

  • email: Email address of the authenticated user.
  • token: Persistent session token stored with the record.
  • lastActivity: Tracks recent activity for idle-timeout validation.
  • cookie: In-memory cookie associated with the active request session.

Example:

final session = AuthSession(email: 'jane@example.com');
Inheritance
Mixed-in types
Available extensions

Constructors

AuthSession({required String email})
Creates a new AuthSession instance for the given email.
AuthSession.fromJson(Map<String, dynamic> json)
Creates an AuthSession from a JSON map.

Properties

getter/setter pair
createdAt DateTime?
Creation timestamp (UTC).
getter/setter pairinherited
disk DatabaseDisk
getter/setter pairinherited
email String
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id int?
Primary key (auto-incremented by backend).
getter/setter pairinherited
lastActivity DateTime
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token String
getter/setter pair
updatedAt DateTime?
Last update timestamp (UTC).
getter/setter pairinherited
uuid String?
UUID for cross-backend identification.
getter/setter pairinherited

Methods

attach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Attaches sibling to this model using the given relationship type.
belongsToMany<T extends Model>({required PivotTable<Model, Model> table, DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves many-to-many related models through a pivot table.
belongsToOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves the parent model for an inverse relationship.
delete({DatabaseDisk? disk}) Future<bool>
Deletes the current instance.
inherited
detach(Model sibling, {required ModelRelationshipType relationship, PivotTable<Model, Model>? table, DatabaseDisk disk = Model.defaultDisk}) Future<bool>

Available on Model, provided by the ModelRelationshipOps extension

Detaches sibling from this model using the given relationship type.
getInstanceTableName() String
inherited
getInstanceTableSingularName() String
inherited
hasMany<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<List<T>>

Available on Model, provided by the ModelRelationships extension

Resolves all one-to-many related models.
hasOne<T extends Model>({DatabaseDisk disk = Model.defaultDisk}) Future<T?>

Available on Model, provided by the ModelRelationships extension

Resolves a one-to-one related model.
load<T extends Model>(ModelRelationshipType relationship, {PivotTable<Model, Model>? table}) Future<Map<String, dynamic>>

Available on Model, provided by the ModelRelationshipOps extension

Loads a relationship and returns this model serialized with the related data embedded.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save({DatabaseDisk? disk}) Future<bool>
Saves the current instance.
inherited
toJson() Map<String, dynamic>
Serializes the session into its standard JSON representation.
override
toMetaJson() Map<String, dynamic>
Serializes the session into a metadata-oriented JSON representation.
override
toString() String
Human-readable string representation.
inherited
update({required Map<String, dynamic> withJson, DatabaseDisk? disk}) Future<bool>
Updates the current instance with new data.
inherited

Operators

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

Static Properties

columnDefinitions Map<String, String>
Defines the database columns required for persisting auth sessions.
getter/setter pair

Static Methods

check(HttpRequest request) Future<bool>
Determines whether the request is currently authenticated.
login({required HttpRequest request, required String email, required String password}) Future<bool>
Attempts to authenticate a user and establish a session.
logout(HttpRequest request) Future<bool>
Logs out the current session associated with the request.
middleware(HttpRequest request, Future<void> next()) Future
Middleware that protects routes requiring authentication.
user(HttpRequest request) Future<User?>
Resolves the currently authenticated user from the incoming request.