early otp expiration fix

This commit is contained in:
Yared Yemane 2026-04-25 00:16:05 -07:00
parent bc68326a66
commit 7e26f15bed
3 changed files with 8 additions and 2 deletions

View File

@ -22,7 +22,8 @@ VALUES ($1, $2, $3, $4, $5, $6);
SELECT id, user_id, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at SELECT id, user_id, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at
FROM otps FROM otps
WHERE user_id = $1 WHERE user_id = $1
ORDER BY created_at DESC LIMIT 1; ORDER BY id DESC
LIMIT 1;
-- name: MarkOtpAsUsed :exec -- name: MarkOtpAsUsed :exec
UPDATE otps UPDATE otps

View File

@ -48,7 +48,8 @@ const GetOtp = `-- name: GetOtp :one
SELECT id, user_id, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at SELECT id, user_id, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at
FROM otps FROM otps
WHERE user_id = $1 WHERE user_id = $1
ORDER BY created_at DESC LIMIT 1 ORDER BY id DESC
LIMIT 1
` `
type GetOtpRow struct { type GetOtpRow struct {

View File

@ -50,6 +50,10 @@ func (s *Store) GetOtp(ctx context.Context, userID int64) (domain.Otp, error) {
} }
return domain.Otp{}, err return domain.Otp{}, err
} }
if !row.ExpiresAt.Valid {
return domain.Otp{}, domain.ErrOtpNotFound
}
return domain.Otp{ return domain.Otp{
ID: row.ID, ID: row.ID,
UserID: row.UserID, UserID: row.UserID,