verifyEmail static method
Implementation
static Future<bool> verifyEmail(String token) async {
await ensureFrameworkTablesExist();
final tokenHash = Hashing().hash(token);
final qb = QueryBuilder(table: 'email_verification_tokens');
final tokenRecord = await qb
.where('token', '=', tokenHash)
.where('expires_at', '>', DateTime.now().toIso8601String())
.first();
if (tokenRecord == null) {
return false;
}
final email = tokenRecord['email'] as String;
// Only update email_verified_at if the column exists
final emailVerifiedAtExists =
await _columnExists(config.table, 'email_verified_at');
if (emailVerifiedAtExists) {
await QueryBuilder(table: config.table)
.where(config.emailColumn, '=', email)
.update({
'email_verified_at': DateTime.now().toIso8601String(),
});
}
await qb.where('token', '=', tokenHash).delete();
return true;
}