使用Firebase登出 [英] Signing out using Firebase
问题描述
我正在使用通过社交媒体帐户进行的Firebase身份验证.注册后,我无法注销.
I am using firebase authentication using social media accounts. After signing up, I am unable to log out.
以下是我的Javascript代码:
The following is my Javascript code:
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "*******",
authDomain: "******",
databaseURL: "******",
projectId: "*******",
storageBucket: "******",
messagingSenderId: "*******"
};
firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.displayName;
var email = user.email;
var photoURL = user.photoURL;
user.getToken().then(function(accessToken) {
console.debug('user', user);
document.getElementById('sign-in-status').textContent = 'Signed in';
document.getElementById('name').textContent = JSON.stringify( displayName )
document.getElementById('email').textContent = JSON.stringify(email)
document.getElementById('account-details').textContent = JSON.stringify({
displayName: displayName,
email: email,
photoURL: photoURL
});
});
} else {
console.log('not logged in');
/*document.getElementById('sign-in-status').textContent = 'Signed out';
document.getElementById('sign-in').textContent = 'Sign in';
document.getElementById('account-details').textContent = 'null';
*/
}
});
// User is signed out.
firebase.auth().signOut().then(function() {
// Sign-out successful.
signOutSuccessUrl: 'https://url.html'
}).catch(function(error) {
// An error happened.
});
</script>
在html中,我通过以下方式调用它:< button class ="btn btn-primary" onclick ="signOut()">< i class ="fa fa-sign-out">/i>注销</button>
And in the html I am calling it by:
<button class="btn btn-primary" onclick="signOut()"><i class="fa fa-sign-out">/i> Log out</button>
但是,单击按钮后没有任何反应.
But on clicking the button nothing happens.
我什至尝试将签出段放入函数中,但这无济于事.
I even tried putting the signout segment in a function, but that didn't help.
任何帮助将不胜感激.谢谢.
Any kind of help would be greatly appreciated. Thanks.
推荐答案
如果您的点击事件处理程序调用了 signOut
方法,则必须在某个位置进行定义.像:
if your click event handler calls a signOut
method, then you have to define it somewhere. like:
window.signOut = function signOut(_e) {
firebase.auth().signOut().then(function() {
// Sign-out successful.
}).catch(function(error) {
// An error happened.
});
}
这篇关于使用Firebase登出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!