Gabriele Sabatino
Gabriele Sabatino

Reputation: 146

firebase issue with auth

I have an issue with firebase auth, it gives me this error:

TypeError: app.auth is not a function. (In 'app.auth()', 'app.auth' is undefined)

I write these lines of code:

import firebase from 'firebase/compat/app' 
import "firebase/auth"

const app = firebase.initializeApp({
    apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
    authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
    projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
    storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
    messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
    appId: process.env.REACT_APP_FIREBASE_APP_ID
})

export const auth = app.auth()
export default app

I tryed to replace with require the import of firebase/auth but it doesn't work, I tryed to uninstall and reinstall all node_modules but it didn't work, somebody can help me?

Upvotes: 1

Views: 277

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50830

If you want to use the name-spaced syntax from V8 then use compat version of auth SDK as well:

import firebase from 'firebase/compat/app' 
import "firebase/compat/auth"
//                ^^^

I would recommend upgrading to the new Modular SDK for better performance and also the compat versions will be removed in upcoming updates.


import { initiliazeApp } from 'firebase/app' 
import { getAuth } from 'firebase/auth'

const app = initializeApp({...config})

export const auth = getAuth(app)
export default app

Upvotes: 2

Related Questions