Add and verify a user's phone number
Account onboarding
Clerk · Class
PhoneNumber represents a user's phone number and its verification state. Its API supports adding numbers, completing SMS OTP verification, formatting them as E.164 values, and using them for multi-factor authentication.
PhoneNumber represents one of a user's phone numbers and tracks its verification state. Create or access the number, start verification to send an SMS OTP, then submit that OTP to finish verification; the number can also support multi-factor authentication.
PhoneNumberconst phoneNumber = user.phoneNumbers[0];
await phoneNumber.prepareVerification();
await phoneNumber.attemptVerification({ code: otp });
console.log(phoneNumber.toString());Starts SMS verification, submits the received OTP, then formats the verified number for display.
Account onboarding
Identity assurance
Account security
Communication
PhoneNumber models a user's phone number and its verification state. Verification begins with prepareVerification(), which sends an SMS OTP, and ends with attemptVerification() using that OTP.
Follow-up: How can it participate in MFA? It can be used as an additional verification factor during sign-in.
The object can be used as proof of identity or as a contact method. Verification establishes that the number belongs to the rightful owner.
Follow-up: What must an implementation avoid? It should not rely on an unverified number for identity assurance.
The documented API includes create() for adding a phone number to the current user. After creation, the number's verification flow can be initiated and completed.
Follow-up: What other representation is available? toString() returns the number in E.164 format, including country code and number.
UserVerificationIdentificationLinkMulti-factor authentication