Skip to content

Firebase Auth errorFirebase Auth: auth/invalid-verification-code

auth/invalid-verification-code is the Firebase Auth error for an SMS code that doesn’t match the code Firebase sent for that verification. It usually comes from a typo, an older code after a resend, or a fictional test number with a different code.

Short answer

Keep the ConfirmationResult or verification ID from the latest signInWithPhoneNumber call, and confirm the code against that one. Strip spaces from the input, let the user resend, and for fictional test numbers enter the code set in the Firebase console.

Rather not fix it yourself? App Fix Ticket starts with a fixed-price diagnosis, then a fixed price for the fix before any fix work.

Why Firebase rejects the code, and the fix

  1. 01

    The user typed the wrong code

    “sign in the user by passing the code to the confirm method of the ConfirmationResult object” Firebase, Phone authentication (web)

    Six digits are easy to mistype. Show a clear message, keep the input, and offer a resend after a short wait.

    try {
      const result = await confirmationResult.confirm(code.replace(/\s/g, ''));
    } catch (error) {
      if (error.code === 'auth/invalid-verification-code') {
        showMessage('That code doesn’t match. Check the SMS or request a new code.');
      }
    }
  2. 02

    An old code after a resend

    After a resend, the user may type the code from the first SMS, which belongs to the earlier verification. Always confirm against the newest ConfirmationResult, and tell the user to use the latest message.

  3. 03

    The wrong verification ID is used

    On Android and iOS, an app restart or a screen rebuild can drop the verification ID or leave an older one in use. A missing or invalid ID gives auth/missing-verification-id or auth/invalid-verification-id; an older ID with a new code fails as a mismatch. Keep the latest ID somewhere that survives.

  4. 04

    A fictional test number uses its own code

    “You can set up fictional phone numbers for development using the Firebase console.” Firebase, Test with fictional phone numbers

    Also check: test numbers set in the console only accept the code you set there. No real SMS is sent to them.

Checked against the vendor’s docs on : Firebase docs: Phone authentication (web).

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
All 127 Fiverr reviews

Related: Firebase auth/invalid-phone-number · Firebase phone auth invalid-app-credential · Firebase auth/missing-or-invalid-nonce · Firebase auth/invalid-action-code

Questions

More on this error

Is an expired code the same error?

No. An expired code gives auth/code-expired. Ask the user to request a new code.

Do fictional numbers cost SMS quota?

No. Firebase says fictional numbers let you test without consuming your usage quota and without sending a real SMS.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.