mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-17 19:05:13 +00:00
feat: Add SMS country code selector to SMT OTP (LoginV1) (#11373)
<!-- Please inform yourself about the contribution guidelines on submitting a PR here: https://github.com/zitadel/zitadel/blob/main/CONTRIBUTING.md#submit-a-pull-request-pr. Take note of how PR/commit titles should be written and replace the template texts in the sections below. Don't remove any of the sections. It is important that the commit history clearly shows what is changed and why. Important: By submitting a contribution you agree to the terms from our Licensing Policy as described here: https://github.com/zitadel/zitadel/blob/main/LICENSING.md#community-contributions. --> # Which Problems Are Solved - This adds rudimentary country code handling for LoginV1 SMS OTP - Previously defaulting to CH with no prompt to user causing e.g UK (+44) based numbers to be re-routed to CH. (+41) # Additional Context - Support for SMS OTP is not complete for LoginV2 (according to latest support email) Tested with Twilio on both UK + DE # . Appears to work. - Closes #8891 <img width="544" height="485" alt="image" src="https://github.com/user-attachments/assets/84d31bd8-8863-465f-8860-b51602439dfb" /> <img width="858" height="1298" alt="Screenshot 2026-01-16 at 11 23 22" src="https://github.com/user-attachments/assets/4bf16f0b-2fec-4d63-95b0-f0b73f3a131a" /> --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
Silvan
parent
30d91cde58
commit
597f385ca4
@@ -12,17 +12,20 @@ const (
|
||||
|
||||
type smsInitData struct {
|
||||
userData
|
||||
Edit bool
|
||||
MFAType domain.MFAType
|
||||
Phone string
|
||||
Edit bool
|
||||
MFAType domain.MFAType
|
||||
Phone string
|
||||
CountryCode string
|
||||
CountryCodes []domain.CountryCode
|
||||
}
|
||||
|
||||
type smsInitFormData struct {
|
||||
Edit bool `schema:"edit"`
|
||||
Resend bool `schema:"resend"`
|
||||
Phone string `schema:"phone"`
|
||||
NewPhone string `schema:"newPhone"`
|
||||
Code string `schema:"code"`
|
||||
Edit bool `schema:"edit"`
|
||||
Resend bool `schema:"resend"`
|
||||
Phone string `schema:"phone"`
|
||||
NewPhone string `schema:"newPhone"`
|
||||
Code string `schema:"code"`
|
||||
CountryCode string `schema:"countryCode"`
|
||||
}
|
||||
|
||||
// handleRegisterOTPSMS checks if the user has a verified phone number and will directly add OTP SMS as 2FA.
|
||||
@@ -57,6 +60,10 @@ func (l *Login) renderRegisterSMS(w http.ResponseWriter, r *http.Request, authRe
|
||||
data.baseData = l.getBaseData(r, authReq, translator, "InitMFAOTP.Title", "InitMFAOTP.Description", err)
|
||||
data.profileData = l.getProfileData(authReq)
|
||||
data.MFAType = domain.MFATypeOTPSMS
|
||||
data.CountryCodes = domain.GetCountryCodes(translator.Lang(r))
|
||||
if data.CountryCode == "" {
|
||||
data.CountryCode = "CH" // default to Switzerland
|
||||
}
|
||||
l.renderer.RenderTemplate(w, r, translator, l.renderer.Templates[tmplMFASMSInit], data, nil)
|
||||
}
|
||||
|
||||
@@ -75,7 +82,7 @@ func (l *Login) handleRegisterSMSCheck(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := setUserContext(r.Context(), authReq.UserID, authReq.UserOrgID)
|
||||
// save the current state
|
||||
data := &smsInitData{Phone: formData.Phone}
|
||||
data := &smsInitData{Phone: formData.Phone, CountryCode: formData.CountryCode}
|
||||
|
||||
if formData.Edit {
|
||||
data.Edit = true
|
||||
@@ -95,7 +102,15 @@ func (l *Login) handleRegisterSMSCheck(w http.ResponseWriter, r *http.Request) {
|
||||
if formData.Code == "" {
|
||||
data.Phone = formData.NewPhone
|
||||
if formData.NewPhone != formData.Phone {
|
||||
_, err = l.command.ChangeUserPhone(ctx, authReq.UserID, formData.NewPhone, l.userCodeAlg)
|
||||
// Normalize phone with selected country code before saving
|
||||
normalizedPhone, normErr := domain.PhoneNumber(formData.NewPhone).NormalizeWithRegion(formData.CountryCode)
|
||||
if normErr != nil {
|
||||
data.Edit = true
|
||||
l.renderRegisterSMS(w, r, authReq, data, normErr)
|
||||
return
|
||||
}
|
||||
data.Phone = string(normalizedPhone)
|
||||
_, err = l.command.ChangeUserPhone(ctx, authReq.UserID, string(normalizedPhone), l.userCodeAlg)
|
||||
if err != nil {
|
||||
// stay in edit more
|
||||
data.Edit = true
|
||||
|
||||
Reference in New Issue
Block a user