Home > @firebase/auth > signInWithPhoneNumber
signInWithPhoneNumber() function
Asynchronously signs in using a phone number.
Signature:
export declare function signInWithPhoneNumber(auth: Auth, phoneNumber: string, appVerifier: ApplicationVerifier): Promise<ConfirmationResult>;
Parameters
Parameter | Type | Description |
---|---|---|
auth | Auth | The Auth instance. |
phoneNumber | string | The user's phone number in E.164 format (e.g. +16505550101). |
appVerifier | ApplicationVerifier | The ApplicationVerifier. |
Returns:
Promise<ConfirmationResult>
Description
This method sends a code via SMS to the given phone number, and returns a ConfirmationResult. After the user provides the code sent to their phone, call ConfirmationResult.confirm() with the code to sign the user in.
For abuse prevention, this method also requires a ApplicationVerifier. This SDK includes a reCAPTCHA-based implementation, RecaptchaVerifier.
Example
// 'recaptcha-container' is the ID of an element in the DOM.
const applicationVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
// Obtain a verificationCode from the user.
const credential = await confirmationResult.confirm(verificationCode);