身份验证 - JavaScript - 注销问题 [英] Authentication - JavaScript - Logout issue

查看:128
本文介绍了身份验证 - JavaScript - 注销问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  firebase.auth()。onAuthStateChanged(user => {
if(user){
console.log('log in');
window.location.href ='event_list.html'
}});

btnLogout.addEventListener('click',e => {
firebase.auth()。signOut()。then(function(){
console.log( );
window.location.href ='index.html';
},function(error){
//
});;

});

登录功能正常,但如果我正在尝试注销 - 用户可能正确注销 - 返回登录/注册网站,但立即我重定向到event_list.html仍然登录用户。



我登录/注册网站是 - index.html



我想注销并放入其他数据 - 登录/传递。另外一个问题是:如何获取电子邮件变量这个脚本,并在其他JavaScript脚本中使用它?



我想做横幅 - 嗨(用户的邮件实际登录),欢迎回来,并将其插入到我的所有HTML网站。

解决方案

我也是Firebase的新手,但是firebase.auth()。signOut b $ b为了确定用户是否登录,可以使用 onAuthStateChanged 事件。如果传递的参数为null,这意味着如果你有一个有效的值用户注销,那么你可以解析用户从

前:(我还没有尝试过,但这应该工作)

  firebase.auth()。onAuthStateChanged(user => {
if(user){
console.log('User Logged in:'+ user);
window.location.href ='event_list.html'
} else {
console.log('User Not Logged in');
window.location.href ='index.html';
}
});

btnLogout.addEventListener('click',e => {
firebase.auth()。signOut();
});


I need some help with my problem.

firebase.auth().onAuthStateChanged(user => {
    if(user) {
    console.log('log in');
    window.location.href ='event_list.html'
    }});

btnLogout.addEventListener('click', e => {
    firebase.auth().signOut().then(function() {
        console.log("not log in");
        window.location.href = 'index.html';
    }, function(error) {
    //
    });;

});

Logging in works correctly but if I'm trying logout - user probably logout correctly - back to login/signup site but immediately I'm redirecting to "event_list.html" as still logged in user.

My sign in/sign up site is - index.html

I want logout and put other data - login/pass.

One other question: How can I get email variable from this script and use it in other JavaScript script?

I want do banner - Hi (mail of user actually log in), Welcome back and insert it to all my HTML sites.

解决方案

I'm also new to Firebase but firebase.auth().signOut() should do the trick for you And in-order to identify if the user is logged in you can use the onAuthStateChanged event. If the passed parameter is null which means user is logged out if you have a valid value then you can resolve the user from that

ex: (I have not tried this but this should work)

firebase.auth().onAuthStateChanged(user => {
    if(user) {
        console.log('User Logged in :' + user );
        window.location.href ='event_list.html'
    }else{
        console.log('User Not Logged in');
        window.location.href = 'index.html';
    }
});

btnLogout.addEventListener('click', e => {
    firebase.auth().signOut();
});

这篇关于身份验证 - JavaScript - 注销问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆