Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
Firebase Auth Multifactor - user object not returning multiFactor property

I'm trying to add MFA inside my web app and the multiFactor property is missing. Check the code:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.2/firebase-app.js";
import { getAuth, RecaptchaVerifier, PhoneAuthProvider, signInWithEmailAndPassword } 
    from "https://www.gstatic.com/firebasejs/9.6.2/firebase-auth.js";

const firebaseConfig = {
    ...
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

auth.onAuthStateChanged((user) => {
    const userEl = document.getElementById('user');
    if (user) {
            userEl.innerHTML = `${user.email} logged in. ${JSON.stringify(
            user.multiFactor.enrolledFactors
        )}`;
    } else {
        userEl.innerHTML = 'signed out';
    }
});

window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {
    'size': 'invisible',
    'callback': (response) => {
        console.log('captcha solved!');
    }
}, auth);

const enrollBtn = document.getElementById('enroll-button');

enrollBtn.onclick = () => {
    signInWithEmailAndPassword(auth, 'blabla@gmail.com', 'foobar').then(() => {
        const user = auth.currentUser;
        if (!user) {
            return alert('User not logged!');
        }

        const phoneNumber = document.getElementById('enroll-phone').value;

        console.log(user);

        user.multiFactor.getSession().then((session) => {
            const phoneOpts = {
                phoneNumber,
                session,
            };

            const phoneAuthProvider = new PhoneAuthProvider();

            phoneAuthProvider.verifyPhoneNumber(
                phoneOpts,
                window.recaptchaVerifier
            ).then((verificationId) => {
                window.verificationId = verificationId;
                alert('sms text sent!');
            });
        });
    });
};

In the code above the user.multiFactor is undefined. The signIn is returning the user normally, but without this property.

error on console: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getSession')

The Firebase project have MFA enabled: enter image description here

**************** UPDATE *******************

Apparently change the code to this worked:

const mfaUser = multiFactor(user);    
mfaUser.getSession().then((session) => {

But now I'm getting this error when I call verifyPhoneNumber:

VM21778 index.html:315 TypeError: Cannot read properties of undefined (reading 'tenantId')
    at _addTidIfNecessary (firebase-auth.js:1934:14)
    at startEnrollPhoneMfa (firebase-auth.js:6778:125)
    at _verifyPhoneNumber (firebase-auth.js:8500:40)

However I'm not using Multi-Tenancy option, this is disabled in my project.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Changed to:

const mfaUser = multiFactor(user);    
mfaUser.getSession().then((session) => {

and:

const phoneAuthProvider = new PhoneAuthProvider(auth);

I don't know if Firebase Auth docs is deprecated or I'm doing something different. XD

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!