Bird
Raised Fist0
Firebasecloud~5 mins

Phone number authentication in Firebase - Commands & Configuration

Choose your learning style10 modes available
Introduction
Phone number authentication lets users sign in using their phone number. It sends a code via SMS to verify the user without needing a password.
When you want users to sign in quickly without creating a password.
When you want to verify users by their phone number for security.
When your app targets users who prefer SMS verification over email.
When you want to reduce friction in the sign-in process on mobile devices.
When you want to support multi-factor authentication using phone numbers.
Config File - firebase.json
firebase.json
{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
  },
  "auth": {
    "signInMethods": ["phone"]
  }
}

This file configures Firebase hosting and enables phone sign-in method under authentication settings.

hosting.public: folder for web files.

auth.signInMethods: enables phone number sign-in.

Commands
Log in to your Firebase account to access your projects and deploy configurations.
Terminal
firebase login
Expected OutputExpected
✔ Success! Logged in as user@example.com
Initialize Firebase Authentication in your project to enable phone number sign-in.
Terminal
firebase init auth
Expected OutputExpected
=== Authentication Setup === ✔ Enabled phone sign-in method Firebase Authentication has been initialized.
Deploy the authentication configuration to Firebase to activate phone number authentication.
Terminal
firebase deploy --only auth
Expected OutputExpected
=== Deploying to 'your-project-id' === ✔ auth: Finished running predeploy script. ✔ auth: deployed phone sign-in method ✔ Deploy complete!
→
--only - Deploy only the specified Firebase feature, here authentication.
Start the phone number sign-in process by sending an SMS code to the specified number.
Terminal
firebase auth:sign-in-with-phone-number +12345678901
Expected OutputExpected
Verification code sent to +12345678901
Key Concept

If you remember nothing else from this pattern, remember: phone number authentication verifies users by sending a code via SMS to their phone.

Common Mistakes
Not enabling phone sign-in method in Firebase console or config.
The authentication will fail because Firebase does not allow phone sign-in without enabling it.
Always enable phone sign-in method in Firebase console or via configuration before deploying.
Using an invalid or incorrectly formatted phone number.
Firebase will not send the verification code if the phone number format is wrong.
Use E.164 format for phone numbers, e.g., +12345678901.
Not deploying authentication changes after updating config.
Changes won't take effect until deployed, so phone sign-in won't work.
Run 'firebase deploy --only auth' after config changes.
Summary
Log in to Firebase and initialize authentication with phone sign-in enabled.
Deploy the authentication configuration to activate phone number sign-in.
Start the sign-in process by sending an SMS verification code to the user's phone.

Practice

(1/5)
1. What is the main purpose of phone number authentication in Firebase?
easy
A. To sign in users using SMS codes without passwords
B. To store phone numbers in the database
C. To send marketing messages to users
D. To verify email addresses

Solution

  1. Step 1: Understand and identify the main purpose of phone number authentication

    It allows users to sign in by receiving a code on their phone via SMS instead of using a password. The main goal is to authenticate users securely and easily using their phone number and SMS code.
  2. Final Answer:

    To sign in users using SMS codes without passwords -> Option A
  3. Quick Check:

    Phone number authentication = SMS sign-in [OK]
Hint: Phone auth uses SMS codes to sign in, not emails [OK]
Common Mistakes:
  • Confusing phone auth with email verification
  • Thinking it stores phone numbers only
  • Assuming it sends marketing SMS
2. Which Firebase method is used to start phone number authentication by sending an SMS code?
easy
A. signInWithEmailAndPassword()
B. signInWithPhoneNumber()
C. sendPasswordResetEmail()
D. verifyPhoneNumber()

Solution

  1. Step 1: Identify the method for phone auth SMS sending and exclude unrelated methods

    Firebase provides signInWithPhoneNumber() to send the SMS code to the user. signInWithEmailAndPassword() is for email login, sendPasswordResetEmail() is for password reset, and verifyPhoneNumber() is not a Firebase client method.
  2. Final Answer:

    signInWithPhoneNumber() -> Option B
  3. Quick Check:

    Send SMS code = signInWithPhoneNumber() [OK]
Hint: Phone auth starts with signInWithPhoneNumber() [OK]
Common Mistakes:
  • Using email sign-in methods for phone auth
  • Confusing password reset with phone auth
  • Assuming verifyPhoneNumber() is a Firebase method
3. What will happen if you try to sign in with phone number authentication without setting up reCAPTCHA verifier in Firebase web?
medium
A. The phone number will be stored but no SMS sent
B. The SMS code will be sent without any issues
C. The user will be signed in automatically
D. Firebase will throw an error requiring reCAPTCHA verification

Solution

  1. Step 1: Understand reCAPTCHA role and predict behavior without it in Firebase phone auth

    Firebase requires reCAPTCHA on web to prevent abuse and verify the user is human before sending SMS. If reCAPTCHA is not set up, Firebase will block the SMS sending and throw an error demanding reCAPTCHA verification.
  2. Final Answer:

    Firebase will throw an error requiring reCAPTCHA verification -> Option D
  3. Quick Check:

    Missing reCAPTCHA = error thrown [OK]
Hint: Web phone auth needs reCAPTCHA or it errors [OK]
Common Mistakes:
  • Assuming SMS sends without reCAPTCHA
  • Thinking user signs in automatically
  • Believing phone number stores without SMS
4. Given this code snippet, what is the error?
const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, appVerifier);
const userCredential = await confirmationResult.confirm(code);
medium
A. phoneNumber should be an email string
B. Using confirm() instead of verify() method
C. Missing reCAPTCHA verifier initialization
D. code variable should be a number, not string

Solution

  1. Step 1: Check parameters and identify common mistake in signInWithPhoneNumber code

    The third parameter must be a valid reCAPTCHA verifier instance (appVerifier) initialized properly. If appVerifier is not initialized or missing, the code will fail even if confirm() is called correctly.
  2. Final Answer:

    Missing reCAPTCHA verifier initialization -> Option C
  3. Quick Check:

    Missing appVerifier init = error [OK]
Hint: Always initialize reCAPTCHA verifier before signInWithPhoneNumber() [OK]
Common Mistakes:
  • Confusing confirm() with verify() method
  • Passing email instead of phone number
  • Assuming code must be number type
5. You want to implement phone number authentication in a React app using Firebase. Which sequence correctly describes the steps to sign in a user?
hard
A. Initialize reCAPTCHA verifier -> call signInWithPhoneNumber() -> send SMS -> confirm code -> sign in user
B. Call signInWithPhoneNumber() -> confirm code -> initialize reCAPTCHA verifier -> sign in user
C. Confirm code -> initialize reCAPTCHA verifier -> call signInWithPhoneNumber() -> sign in user
D. Sign in user -> initialize reCAPTCHA verifier -> call signInWithPhoneNumber() -> confirm code

Solution

  1. Step 1: Outline the correct sequence for implementing phone auth

    Initialize reCAPTCHA verifier first to prevent abuse and required before sending SMS. Call signInWithPhoneNumber() next to send the code to the user's phone. Confirm the code received by user using confirmationResult.confirm(code) to verify and sign in the user.
  2. Final Answer:

    Initialize reCAPTCHA verifier -> call signInWithPhoneNumber() -> send SMS -> confirm code -> sign in user -> Option A
  3. Quick Check:

    reCAPTCHA -> send SMS -> confirm code = correct flow [OK]
Hint: Always start with reCAPTCHA, then send SMS, then confirm code [OK]
Common Mistakes:
  • Calling signInWithPhoneNumber before reCAPTCHA setup
  • Confirming code before SMS sent
  • Trying to sign in before confirmation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard