Phone number management

Verification

If the phone number verification is set up on your account, the user will receive an SMS with a code to verify their phone number. Have a look at the Set and customize verification SMS guide to configure the Signup verification SMS template.

Use the verifyPhoneNumber method to validate the user’s code.

One of the required argument is the user’s access token that you can retrieve through an authorization code request or an implicit flow.

<form id="verification-phone-form" onsubmit="verifyPhoneNumber">
    <div>
        <label for="phone_number">Phone number</label>
        <input type="phone" id="phone_number" name="phone_number">
    </div>
    <div>
        <label for="code">Code</label>
        <input type="text" id="code" name="code">
    </div>
    <button type="submit">Verify</button>
</form>
const ACCESS_TOKEN = 'Here paste the user\'s access token';

function verifyPhoneNumber(event) {
    event.preventDefault();
    const form = event.target('verification-phone-form');
    const formData = new FormData(form);

    client.verifyPhoneNumber({
        accessToken: ACCESS_TOKEN,
        phoneNumber: formData.get('phone_number'),
        verificationCode: formData.get('code')
    });
}

Updating a phone number

The user can change their phone number provided phone number verification is enabled on your account.

The updatePhoneNumber method accepts the new phone number and the user access token that you can retrieve through an authorization code request or an implicit flow.

If the phone_number is unverified, the update is effective immediately. If the phone_number is verified, the user will need to verify the new phone_number before the update takes place.
<form id="update-phone-form" onsubmit="updatePhoneNumber">
    <div>
        <label for="new_phone_number">New phone number</label>
        <input type="phone" id="new_phone_number" name="new_phone_number">
    </div>
    <button type="submit">Update</button>
</form>
const ACCESS_TOKEN = 'Here paste the user\'s access token';

function updatePhoneNumber(event) {
    event.preventDefault();
    const form = event.target('update-phone-form');
    const formData = new FormData(form);

    client.updatePhoneNumber({
        accessToken: ACCESS_TOKEN,
        phoneNumber: formData.get('new_phone_number')
    });
}