question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"TypeError: app.auth is not a function" when using PhoneAuthProvider

See original GitHub issue
import {useEffect} from "react";
import {initializeApp} from "firebase/app";
import {getAuth, PhoneAuthProvider} from "firebase/auth";
import * as firebaseui from 'firebaseui'
import 'firebaseui/dist/firebaseui.css'

function App() {
    const firebaseConfig = {
        ...
    };
    const app = initializeApp(firebaseConfig);

    const uiConfig = {
        signInSuccessUrl: '<url-to-redirect-to-on-success>',
        signInOptions: [
            PhoneAuthProvider.PROVIDER_ID
        ],
        tosUrl: () => alert('Terms of service'),
        privacyPolicyUrl: () => alert('Privacy policy')
    };

    // SOURCE: https://github.com/firebase/firebaseui-web/issues/216#issuecomment-459302414
    const ui = firebaseui.auth.AuthUI.getInstance() || new firebaseui.auth.AuthUI(getAuth());
    useEffect(() => {
        ui.start('#firebaseui-auth-container', uiConfig);
    }, []);

    return (
        <div className="App">
            <div id="firebaseui-auth-container"/>
        </div>
    );
}

export default App;

My project is React and when I run this code, I get this error TypeError: app.auth is not a function. This only happens when I use PhoneAuthProvider.PROVIDER_ID, when I insert GoogleAuthProvider.PROVIDER_ID everything works fine. I tried with multiple devices and environments and I always get the same error. Does my code have any mistakes? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
xil222commented, Nov 9, 2021

@wonsuc I think that would be one of the top priorities.

1reaction
xil222commented, Nov 5, 2021

can you try

import {PhoneAuthProvider} from "firebase/compat/auth"; 
import {initializeApp} from "firebase/compat/app";

using compat library would change the import style see here

Read more comments on GitHub >

github_iconTop Results From Across the Web

app.auth is not a function" when using PhoneAuthProvider ...
This only happens when I use PhoneAuthProvider.PROVIDER_ID, when I insert GoogleAuthProvider.PROVIDER_ID everything works fine. firebase no ...
Read more >
firebase.auth is not a function
As suggested in web get started guide. However, when I try to use firebase.auth() I get an error: console.js:32 TypeError: firebase.
Read more >
PhoneAuthProvider | Firebase JavaScript API reference
Reference for PhoneAuthProvider. ... at Firebase Summit, and learn how Firebase can help you accelerate app development and run your app with confidence....
Read more >
FirebaseUI for Web — Auth
Use the same OAuth client ID used for the Google provider // configured with GCIP or Firebase Auth. clientId: 'xxxxxxxxxxxxxxxxx.apps.googleusercontent.com' }, ...
Read more >
FirebaseRecaptcha
Firebase phone authentication is not possible out of the box using the Firebase JS ... getApp } from 'firebase/app'; import { getAuth, PhoneAuthProvider, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found