控制台显示我有一个意外令牌但我不认为有任何意外令牌。请帮帮我。我花了太多时间试图解决这个问题。下面是代码-
import React from 'react';
import firebase from 'firebase';
export default function App() {
// I have deleted this information because I don't want anyone to access my data
const firebaseConfig = {};
firebase.initializeApp(firebaseConfig);
function signInWithGoogle() {
var google_provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(google_provider)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.log(error);
});
}
return (
<div>
<h1>Google Sign In Authentication</h1>
<button onClick={signInWithGoogle}>Sign In</button>
</div>
);
}
我在提供的代码中看到的唯一问题是您没有导入Firebase Auth SDK。您可以导入它,如下所示:
import firebase from 'firebase';
import "firebase/auth"
也确保您正在使用V8.X.X
与上面的代码或更低。如果您有新的模块化SDKV9.0.0+
,请将导入更改为兼容版本以继续使用现有代码:
import firebase from 'firebase/compat/app';
import "firebase/compat/auth"