【问题标题】:firebase issue with auth身份验证的firebase问题
【发布时间】:2021-11-04 18:49:45
【问题描述】:

我遇到了 firebase 身份验证问题,它给了我这个错误:

TypeError:app.auth 不是函数。 (在 'app.auth()' 中,'app.auth' 是 未定义)

我写了这几行代码:

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

我尝试替换为需要导入 firebase/auth 但它不起作用,我尝试卸载并重新安装所有 node_modules 但它不起作用,有人可以帮助我吗?

【问题讨论】:

  • firebase.auth()?
  • 不工作@Phix
  • 嘿@GabrieleSabatino,我的回答有用吗?如果是,您可以通过单击 (✅) 图标接受它,以便其他人知道问题已解决 :)

标签: javascript reactjs firebase firebase-authentication


【解决方案1】:

如果你想使用 V8 中的命名空间语法,那么也可以使用兼容版本的 auth SDK:

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

我会推荐 upgrading to the new Modular SDK 以获得更好的性能,并且兼容版本将在即将到来的更新中删除。


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

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

export const auth = getAuth(app)
export default app

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2021-12-09
    • 2021-04-21
    • 2020-12-22
    • 2020-11-27
    • 2020-04-18
    • 2016-10-16
    相关资源
    最近更新 更多