gpt4 book ai didi

javascript - 谷歌认证死循环

转载 作者:行者123 更新时间:2023-12-03 05:04:44 26 4
gpt4 key购买 nike

我的 app.js 看起来像这样:

// Initialize Firebase
const config = {
apiKey: //...
authDomain: //...
databaseURL: //...
storageBucket://...
messagingSenderId: //...
};
firebase.initializeApp(config);

}());

function.googleSignin(){
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
}

firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});

但是,现在当我加载页面时,它会自动重定向到谷歌登录(目前,我只希望它们在单击按钮时重定向到登录)。更重要的是,它会无限循环地执行此操作:在我登录后将我重定向到登录页面。

我需要做什么才能使其仅在单击按钮时重定向?并且之后不会自动重定向到谷歌登录?

================================================== ===========================我对网络开发非常陌生,对于如何将谷歌登录集成到我托管在 Firebase 上的应用程序中完全迷失了。我创建了一个带有 Google 登录按钮的弹出窗口。

               <div id="id01" class="modal">
<form class="modal-content animate" action="action_page.php">
<div class="imgcontainer">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
</div>
<div class="loginMsg">
<p>hi there!</p>
<p>log in to post and comment on ride share</p>
</div>
<button class="loginBtn loginBtn--facebook">connect with facebook</button>
<button class="loginBtn loginBtn--google">connect with google </button>
</form>
</div>

我试图理解 Firebase instructions ,但我迷路了。我在代码中的什么位置执行这些步骤?例如,我是否包含“var provider = new firebase.auth.GoogleAuthProvider();”在我的index.html 页面的脚本中?在 app.js 中?当然,我需要按钮来重定向到此登录功能,那么我该怎么做呢?

最佳答案

您不能在同一个按钮点击回调中调用signInWithRedirect和getRedirectResult。

通常,您可以执行以下操作:

对于点击处理程序上的按钮,请执行以下操作:

function.googleSignin(){
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
}

在函数之外设置重定向监听器:

firebase.auth().getRedirectResult().then(function(result) {
if (result.user) {
// User just signed in. you can get the result.credential.
// Update your UI, hide the sign in button.
} else if (firebase.auth().currentUser) {
// User already signed in.
// Update your UI, hide the sign in button.
} else {
// No user signed in, update your UI, show the sign in button.
}
});

关于javascript - 谷歌认证死循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42057767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com