validateAuthSessionForPersistence function
Validates a session record before it is persisted.
Implementation
void validateAuthSessionForPersistence(AuthSessionRecord session) {
if (session.id.trim().isEmpty) {
throw ArgumentError.value(session.id, 'session.id', 'must be non-empty');
}
if (session.tokenHash.trim().isEmpty) {
throw ArgumentError.value(
session.tokenHash,
'session.tokenHash',
'must be non-empty',
);
}
if (session.userId.trim().isEmpty) {
throw ArgumentError.value(
session.userId,
'session.userId',
'must be non-empty',
);
}
if (session.authenticationMethod.trim().isEmpty) {
throw ArgumentError.value(
session.authenticationMethod,
'session.authenticationMethod',
'must be non-empty',
);
}
if (!session.expiresAt.isAfter(session.createdAt)) {
throw ArgumentError.value(
session.expiresAt,
'session.expiresAt',
'must be after createdAt',
);
}
if (session.lastUsedAt.isBefore(session.createdAt)) {
throw ArgumentError.value(
session.lastUsedAt,
'session.lastUsedAt',
'must not be before createdAt',
);
}
}