Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow user to update phone number #421

Merged
merged 3 commits into from
Mar 22, 2022
Merged

fix: allow user to update phone number #421

merged 3 commits into from
Mar 22, 2022

Conversation

kangmingtay
Copy link
Member

@kangmingtay kangmingtay commented Mar 21, 2022

What kind of change does this PR introduce?

  • Fixes PUT /user should allow update of phone field  #390
  • If GOTRUE_SMS_AUTOCONFIRM is enabled, an otp will not be sent to the new phone number, else, an otp will be sent to the new phone number and the user has to verify it first.
  • Added a new verification type called phone_change which when set, will verify if the token sent is valid when compared to the phone_change_token and phone_change_sent_at fields

To-Do

@kangmingtay kangmingtay requested review from awalias and J0 March 21, 2022 17:25
@@ -29,39 +34,51 @@ func (a *API) formatPhoneNumber(phone string) string {
return strings.ReplaceAll(strings.Trim(phone, "+"), " ", "")
}

func (a *API) sendPhoneConfirmation(ctx context.Context, tx *storage.Connection, user *models.User, phone string) error {
// sendPhoneConfirmation sends an otp to the user's phone number
func (a *API) sendPhoneConfirmation(ctx context.Context, tx *storage.Connection, user *models.User, phone, otpType string, smsProvider sms_provider.SmsProvider) error {
Copy link
Member Author

@kangmingtay kangmingtay Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the function signature here to take in an otpType and a smsProvider. The smsProvider was added to the function params to make it easier to test this function with a mock sms provider that implements a stub SendSms method. See TestSendPhoneConfirmation.

@kangmingtay kangmingtay self-assigned this Mar 21, 2022
api/phone.go Show resolved Hide resolved
go.sum Show resolved Hide resolved
@J0
Copy link
Contributor

J0 commented Mar 22, 2022

LGTM, thanks for the PR!

@kangmingtay kangmingtay merged commit b611f1a into master Mar 22, 2022
@kangmingtay kangmingtay deleted the km/update-phone branch March 22, 2022 19:12
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.6.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

awalias added a commit that referenced this pull request Nov 17, 2022
kangmingtay pushed a commit that referenced this pull request Nov 17, 2022
uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
* refactor: sendPhoneConfirmation should accept an otpType and smsProvider

* fix: allow update phone for users endpoint

* fix: add phone change verification method
uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 13, 2024
* refactor: sendPhoneConfirmation should accept an otpType and smsProvider

* fix: allow update phone for users endpoint

* fix: add phone change verification method
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 13, 2024
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 15, 2024
* refactor: sendPhoneConfirmation should accept an otpType and smsProvider

* fix: allow update phone for users endpoint

* fix: add phone change verification method
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PUT /user should allow update of phone field
2 participants