首页 > 解决方案 > Firebase 上的身份验证问题

问题描述

我在 Firebase 的网页上为 Google 添加了一种登录方法,并获得了重定向以成功登录 Google。问题是,登录后我在 Firebase 的身份验证部分看不到任何用户。请帮助。我已经坚持了很长时间。这是 HTML 文件:

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
</head>
<body>
    <button type="button" id="googlebtn" onclick="GoogleLogin();">Google</button>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.6.2/firebase.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.6.2/firebase-analytics.js"></script>

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "AIzaSyA4SJ-R5AK6YUd4Z1hXXQBH-UGb0pLi8ug",
    authDomain: "oshop-c2ca6.firebaseapp.com",
    databaseURL: "https://oshop-c2ca6.firebaseio.com",
    projectId: "oshop-c2ca6",
    storageBucket: "oshop-c2ca6.appspot.com",
    messagingSenderId: "1089602124550",
    appId: "1:1089602124550:web:4607bbd77cffa950eebc87",
    measurementId: "G-64Z9HFJD92"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
</script>
    <script src="google.js" type="text/javascript"></script>

</body>
</html> 

google.js文件:

function GoogleLogin(){
   var provider=new firebase.auth.GoogleAuthProvider();
   firebase.auth().signInWithRedirect(provider).then(function(){

       window.location="index.html";
   }).catch(function(error){
       var errorMessage=error.message;
       alert(errorMessage);
   })
}

标签: javascripthtmlangularjsfirebasefirebase-authentication

解决方案


推荐阅读