verifyNumericCode static method
Verify numeric verification code
Implementation
static Future<bool> verifyNumericCode(String email, String code) async {
await Auth.ensureFrameworkTablesExist();
// Find matching valid record
final record = await QueryBuilder(table: 'email_verification_tokens')
.where('email', '=', email)
.where('expires_at', '>', DateTime.now().toIso8601String())
.first();
if (record == null) {
Log.warning('โ Invalid or expired verification code for $email');
return false;
}
final isValid = Hashing().verify(code, record['token']);
if (!isValid) {
Log.warning('โ Invalid 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();
Log.debug('โ
Email verified successfully: $email');
return true;
}