gpt4 book ai didi

javascript - 未调用 Firebase signInSuccessWithAuthResult

转载 作者:行者123 更新时间:2023-11-29 23:17:57 25 4
gpt4 key购买 nike

我在我的网站上使用 Firebase Auth,但遇到了问题。我想避免登录后自动重定向,据我所知,如果您在回调中返回 false,它不会重定向。我的问题是 signInSuccessWithAuthResult不调用回调。为什么不调用它,是否有更好的方法来实现它?

window.addEventListener('load', function () {
var uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) {
// User successfully signed in.
console.log("sign in success");
// don't redirect automatically
return false;
}
},
signInSuccessUrl: <I dont want to go here>,
signInOptions: [
// Leave the lines as is for the providers you want to offer your users.
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.EmailAuthProvider.PROVIDER_ID
],
// Terms of service url.
tosUrl: '<your-tos-url>',
// Privacy policy url.
privacyPolicyUrl: '<your-privacy-policy-url>'
};

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
user.getIdToken().then(function (accessToken) {
console.log("token retrieved: "+accessToken);
// Send token to your backend via HTTPS
var xhr = new XMLHttpRequest();
xhr.open('POST', '/');
xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText);
document.getElementById('firebaseui-auth-container').hidden=true;
};
xhr.send('token=' + accessToken);
});
}
});
});

最佳答案

在遵循@bojeil 提示后,我更新了库,现在可以使用了。

请注意,登录后页面仍在重新加载。

关于javascript - 未调用 Firebase signInSuccessWithAuthResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51990715/

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