我已经在javascript
中创建了一个Web应用,并在其中添加了firebase
配置。我已在网络应用程序中添加了Google登录。已成功部署它,并且还启用了 Google 登录Firebase
。它工作正常,但是在用户登录后,该用户没有被添加到Firebase Authentication
中。它说“当前项目没有用户”。如何解决呢?请帮忙!!!
控制台窗口显示POST www.googleapis.com 400()错误。请在此处找到屏幕截图。
控制台窗口显示POST 400错误
Firebase身份验证
代码:
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script>
<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"></script>
<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-functions.js"></script>
<!-- Gmail Login Code Start -->
<script>
// Initialize Firebase
var config = {
apiKey: "*****************",
authDomain: "*************.firebaseapp.com",
databaseURL: "https://*******.firebaseio.com",
projectId: "****************",
storageBucket: "***********.appspot.com",
messagingSenderId: "**************"
};
firebase.initializeApp(config);
function login(){
function newLoginHappend(user){
if (user){
//user has signed in
app(user);
document.getElementById("SignOutButton").style = "display:block";
document.getElementById("SignInButton").style = "display:none";
}
else{
}
}
firebase.auth().onAuthStateChanged(newLoginHappend);
}
function login2(){
function newLoginHappend(user){
if (user){
//user has signed in
app(user);
document.getElementById("SignOutButton").style = "display:block";
}
else{
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
}
}
firebase.auth().onAuthStateChanged(newLoginHappend);
}
function app(user){
//user.displayName
//user.email
//user.photoURL
//user.uid
document.getElementById("ClientName").innerHTML = user.displayName;
}
window.onload = login();
</script>
<!-- <button id="SignInButton" style="display:block" onclick='login2()'>Sign In</button>
<button id="SignOutButton" style="display:block" onclick='firebase.auth().signOut();location.reload(true);'>Sign Out</button> -->
<div style="text-align:center;">
<span>
<div class="btn-group">
<a class='btn btn-danger disabled' ><i class="fa fa-google-plus" style="width:16px; height:20px; "></i></a>
<a id="SignInButton" class='btn btn-danger' onclick='login2()' target="_blank" style="width:12em;line-height:20px"> Sign in with Google</a>
</div>
<div class="btn-group">
<a class='btn btn-primary disabled'><i class="fa fa-facebook" style="width:16px; height:20px"></i></a>
<a class='btn btn-primary ' href='' style="width:12em;line-height:20px"> Sign in with Facebook</a>
</div>
</span>
</div>
<!-- Gmail Login Code end -->