[英]Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_0__.app.auth is not a function
ok so ive been building a discord clone with react redux, right now im stuck on the sign in page.好的,所以我一直在用反应 redux 构建 discord 克隆,现在我卡在登录页面上。 it keeps giving me this error "Uncaught TypeError: firebase__WEBPACK_IMPORTED_MODULE_0 _.app.auth is not a function" heres my code in firebase.js它一直给我这个错误“Uncaught TypeError: firebase__WEBPACK_IMPORTED_MODULE_0 _.app.auth is not a function”这是我在 firebase.js 中的代码
import { initializeApp } from "firebase/app";
import { getDatabase } from 'firebase/database';
import { getAuth } from "firebase/auth"
import { GoogleAuthProvider } from "firebase/auth";
const firebaseConfig = {
apiKey: "AIzaSyD0RxEfG1qZ4Qsoelw5E6J0rIaJSP4BbXQ",
authDomain: "diacromb.firebaseapp.com",
projectId: "diacromb",
storageBucket: "diacromb.appspot.com",
messagingSenderId: "237625612351",
appId: "1:237625612351:web:2527b57f858d5a4688008a",
measurementId: "G-3DEREK47Q2"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const auth = getAuth();
const provider = new GoogleAuthProvider();
export {auth , app };
export {provider};
export default db;
heres my code for Login.js这是我的 Login.js 代码
import { Button } from '@material-ui/core'
import { auth, app } from './firebase'
import { provider } from './firebase'
import { signInWithPopup } from "firebase/auth"
import React from 'react'
import './Login.css'
function Login() {
/* const signIn = () =>{
const googleAuthProvider = new GoogleAuthProvider();
app.auth().signInWithPopup(googleAuthProvider);
} */
const signIn = ()=>{
var google_provider = provider;
app.auth().signInWithPopup(provider)
.then((re)=>{
console.log(re)
})
.catch((err)=>{
console.log(err)
})
}
return (
<div className='login'>
<h2> I am the login page</h2>
<Button onClick={signIn}>Sign In</Button>
</div>
);
}
export default Login
I have no idea whats going on, ive read some other posts and people are saying to install older versions of firebase, I tried to do that and it still didnt work.我不知道发生了什么,我阅读了其他一些帖子,人们说要安装旧版本的 firebase,我试图这样做,但它仍然没有用。 Ive been stumped on this for nearly 2 days now我已经为此困扰了将近 2 天了
I assume you are using firebase 9. there you have to use js modules.我假设你使用的是 firebase 9. 你必须使用 js 模块。
https://firebase.google.com/docs/web/modular-upgrade https://firebase.google.com/docs/web/modular-upgrade
import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.email;
// The AuthCredential type that was used.
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.