Skip to content

Commit 8bf17f6

Browse files
committed
chore: refactor
1 parent 30498dc commit 8bf17f6

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

internal/api/verify.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -961,25 +961,27 @@ func validateUserForOTT(params *VerifyParams, ott *models.OneTimeToken, user *mo
961961
return mismatch.WithInternalMessage("user audience does not match")
962962
}
963963

964-
// Pick the identifier on the user record that this verify type is bound to,
965-
// then compare it against the identifier in the request.
966-
var expected, actual, field string
967964
switch params.Type {
968965
case smsVerification:
969-
expected, actual, field = user.GetPhone(), params.Phone, "phone"
966+
if params.Phone == "" || user.GetPhone() != params.Phone {
967+
return mismatch.WithInternalMessage("user phone does not match")
968+
}
970969
case phoneChangeVerification:
971-
expected, actual, field = user.PhoneChange, params.Phone, "phone"
970+
if params.Phone == "" || user.PhoneChange != params.Phone {
971+
return mismatch.WithInternalMessage("user phone does not match")
972+
}
972973
case mail.EmailChangeVerification:
973-
expected, actual, field = user.EmailChange, params.Email, "email"
974+
expected := user.EmailChange
974975
if ott.TokenType == models.EmailChangeTokenCurrent {
975976
expected = user.GetEmail()
976977
}
978+
if params.Email == "" || !strings.EqualFold(expected, params.Email) {
979+
return mismatch.WithInternalMessage("user email does not match")
980+
}
977981
default: // Signup, Invite, Recovery, MagicLink
978-
expected, actual, field = user.GetEmail(), params.Email, "email"
979-
}
980-
981-
if actual == "" || !strings.EqualFold(expected, actual) {
982-
return mismatch.WithInternalMessage("user %s does not match", field)
982+
if params.Email == "" || !strings.EqualFold(user.GetEmail(), params.Email) {
983+
return mismatch.WithInternalMessage("user email does not match")
984+
}
983985
}
984986
return nil
985987
}

0 commit comments

Comments
 (0)