Skip to main content

Change Phone

Change Phone

You can change the phone number of the user by calling the changePhone method.

const currentPassword = "123456";
const newPhone = "+17777777777";

// Change phone number of the user
const result = await agnost.auth.changePhone(currentPassword, newPhone)
Example response
{
"user": {
"_id": "6235f78c0874df80013caea2",
"provider": "agnost",
"providerUserId": "6235f78c0874df80013caea2",
"phone": "+15555555555",
"signUpAt": "2022-03-19T15:32:28.958Z",
"lastLoginAt": "2022-03-19T15:38:42.093Z",
"phoneVerified": true,
"name": "Rooby"
},
"errors": null
}
info

If phone confirmation is enabled in your App settingsAuthentication view of Studio

  • It sends a confirmation SMS code to the new phone number and returns the current user's info.
  • Until the SMS code is verified by calling the verifyPhone method, the user's phone number will not be changed to the new one.
  • After sending the SMS code by calling this method, you need to show a form to the user to enter this SMS code and call verifyPhone method with the new phone number and the code to change user's phone number to the new one
note

If phone confirmation is disabled in your App settingsAuthentication view of Studio, it immediately updates the user's phone number and returns back the updated user data.

Parameters

Here you can find parameters for the changePhone method.

#

Name

Data type

Required

Description

1currentPasswordStringYesThe current password of the user.
2newPhoneStringYesThe new phone number of the user.
note

An active user session is required (e.g., user needs to be logged in) to call this method.

Verify Phone

After user receives the phone number verification code sent through calling changePhone method, you can use verifyPhone method to verify the new phone number.

const newPhone = "+177777777777";
const code = "504674";

// Verify the new phone number using the verification code sent to the
// new phone number over SMS and return the updated user data

const result = await agnost.auth.verifyPhone(newPhone, code)
Example response
{
"user": {
"_id": "6235f78c0874df80013caea2",
"provider": "agnost",
"providerUserId": "6235f78c0874df80013caea2",
"phone": "+17777777777",
"signUpAt": "2022-03-19T15:32:28.958Z",
"lastLoginAt": "2022-03-19T15:38:42.093Z",
"phoneVerified": true,
"name": "Rooby"
},
"session": null,
"errors": null
}

Parameters

Here you can find parameters for the verifyPhone method.

#

Name

Data type

Required

Description

1phoneStringYesThe new phone number of the user.
2codeStringYesThe verification SMS code.