Skip to content

Commit

Permalink
fix: resend email change & phone change issues (#1100)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Fix #1095 where `/resend` doesn't work if the user initially signed up
with a phone number and is trying to resend an email change email
  • Loading branch information
kangmingtay authored May 8, 2023
1 parent 965feb9 commit 184fa38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions internal/api/resend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func (p *ResendConfirmationParams) Validate() error {
return badRequestError("Missing one of these types: signup, email_change, sms, phone_change")

}
if p.Email == "" && (p.Type == signupVerification || p.Type == emailChangeVerification) {
if p.Email == "" && p.Type == signupVerification {
return badRequestError("Type provided requires an email address")
}
if p.Phone == "" && (p.Type == smsVerification || p.Type == phoneChangeVerification) {
if p.Phone == "" && p.Type == smsVerification {
return badRequestError("Type provided requires a phone number")
}

Expand Down Expand Up @@ -132,13 +132,13 @@ func (a *API) Resend(w http.ResponseWriter, r *http.Request) error {
}
return a.sendPhoneConfirmation(ctx, tx, user, params.Phone, phoneConfirmationOtp, smsProvider, sms_provider.SMSProvider)
case emailChangeVerification:
return a.sendEmailChange(tx, config, user, mailer, params.Email, referrer, config.Mailer.OtpLength, models.ImplicitFlow)
return a.sendEmailChange(tx, config, user, mailer, user.EmailChange, referrer, config.Mailer.OtpLength, models.ImplicitFlow)
case phoneChangeVerification:
smsProvider, terr := sms_provider.GetSmsProvider(*config)
if terr != nil {
return terr
}
return a.sendPhoneConfirmation(ctx, tx, user, params.Phone, phoneChangeVerification, smsProvider, sms_provider.SMSProvider)
return a.sendPhoneConfirmation(ctx, tx, user, user.PhoneChange, phoneChangeVerification, smsProvider, sms_provider.SMSProvider)
}
return nil
})
Expand Down
6 changes: 3 additions & 3 deletions internal/api/resend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func (ts *ResendTestSuite) TestResendValidation() {
},
},
{
desc: "Type & phone mismatch",
desc: "Phone & email change type",
params: map[string]interface{}{
"type": "email_change",
"phone": "+123456789",
},
expected: map[string]interface{}{
"code": http.StatusBadRequest,
"message": "Type provided requires an email address",
"code": http.StatusOK,
"message": nil,
},
},
{
Expand Down

0 comments on commit 184fa38

Please sign in to comment.