verifyNumericCode static method
Verify numeric verification code
Implementation
static Future<bool> verifyNumericCode(String email, String code) async {
await Auth.ensureFrameworkTablesExist();
final codeHash = Hashing().hash(code);
// Find matching valid record
final record = await QueryBuilder(table: 'email_verification_tokens')
.where('email', '=', email)
.where('token', '=', codeHash)
.where('expires_at', '>', DateTime.now().toIso8601String())
.first();
if (record == null) {
print('❌ Invalid or expired verification code for $email');
return false;
}
// Mark email as verified
final emailVerifiedAtExists =
await Auth.columnExists(Auth.config.table, 'email_verified_at');
if (emailVerifiedAtExists) {
await QueryBuilder(table: Auth.config.table)
.where(Auth.config.emailColumn, '=', email)
.update({
'email_verified_at': DateTime.now().toIso8601String(),
});
}
// 🧹 Delete used code
await QueryBuilder(table: 'email_verification_tokens')
.where('email', '=', email)
.delete();
print('✅ Email verified successfully: $email');
return true;
}