【发布时间】:2017-06-25 02:27:53
【问题描述】:
我正在尝试创建一个网站,在该网站上单击一个按钮以使用 google 登录,然后转到一个新的 html 页面。
但是,当新的 google 登录窗口弹出时,它立即关闭,html 页面发生变化。
我确实希望更改 html 页面,但是:我需要 google 登录吗
先上班?有没有办法等到用户登录后再转到新页面?
我在想是否有一个布尔方法来查看登录是否成功,但我找不到。
你能帮帮我吗?
<html>
<head>
//connect to css and javascript file
<link rel="stylesheet" href="hackathon.css">
<script src=scripts.js></script>
</head>
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyAOWTFIhpydI27RMa_JzOW0Ffyajb9sTqg",
authDomain: "teach-and-learn-cd50e.firebaseapp.com",
databaseURL: "https://teach-and-learn-cd50e.firebaseio.com",
projectId: "teach-and-learn-cd50e",
storageBucket: "",
messagingSenderId: "412721016471"
};
firebase.initializeApp(config);
</script>
<br><br><br><br><br><br><br><br><br>
//create the header
<p><center><font face="Verdana" size="7" color="white">Teach and Learn</font></p>
//login button
<button class="button1">Log In</button>
//google sign in
<script type="text/javascript">
button=document.querySelector('button')
database=firebase.database()
reference=database.ref()
button.onclick=function(){
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
})
//immediately goes to this page without giving the use
//opportunity to sign in
//main.html is loaded and the sign in window is closed
window.location.href="./main.html";
</script>
</html>
【问题讨论】:
-
你可能已经登录了谷歌?
标签: javascript html firebase-authentication google-authentication