save method
Saves token after normalizing its user and email values.
User IDs are trimmed, email addresses are trimmed and lower-cased, and only a digest of the raw token is retained. Existing records for the normalized user are replaced. Blank fields throw an ArgumentError. Expired records are pruned and the oldest record is evicted at capacity.
Implementation
@override
Future<void> save(AuthEmailChangeToken token) async {
final userId = token.userId.trim();
final email = token.newEmail.trim().toLowerCase();
if (userId.isEmpty || email.isEmpty || token.token.trim().isEmpty) {
throw ArgumentError('Email-change token fields must be non-empty.');
}
final now = _clock().toUtc();
_prune(now);
_records.removeWhere((_, record) => record.userId == userId);
while (_records.length >= maxTokens) {
_removeOldest();
}
_records[hashOpaqueToken(token.token)] = _EmailChangeRecord(
userId: userId,
newEmail: email,
expiresAt: token.expiresAt.toUtc(),
);
}