Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular/fire authState.subscribe不响应注销_Angular_Firebase_Firebase Authentication_Angularfire - Fatal编程技术网

Angular/fire authState.subscribe不响应注销

Angular/fire authState.subscribe不响应注销,angular,firebase,firebase-authentication,angularfire,Angular,Firebase,Firebase Authentication,Angularfire,我是angular的新手,我正在尝试通过firebase认证。我已经建立了登录/注册和注销。它现在可以正常工作了,但现在我想显示一个导航栏(完全独立的组件),它有一个登录按钮和注销按钮。我需要根据用户的身份状态切换这些按钮。所以我使用了authState上的subscribe。但它只在用户登录时起作用。它不会在用户注销时触发。当用户注销时,它应该返回null,对吗?我在authService中检查了authState,用户注销后它为null。那么我做错了什么 这是我的密码 auth.servic

我是angular的新手,我正在尝试通过firebase认证。我已经建立了登录/注册和注销。它现在可以正常工作了,但现在我想显示一个导航栏(完全独立的组件),它有一个登录按钮和注销按钮。我需要根据用户的身份状态切换这些按钮。所以我使用了authState上的subscribe。但它只在用户登录时起作用。它不会在用户注销时触发。当用户注销时,它应该返回null,对吗?我在authService中检查了authState,用户注销后它为null。那么我做错了什么

这是我的密码

auth.service.ts 导航组件
我很确定您的authService
doLogout()
正在返回一个承诺的承诺

auth.signout()
已返回承诺

我认为您的
doLogout()
函数应该是:

return this.mAuth.auth.signout()
Sidenote:我遇到了完全相同的问题,这是因为authstate在某种程度上受到
路由器的影响。我的错误是:

this.authstate.signout();
this.router.navigate(['/']);
但是有了上面的代码,
authstate
实际上永远不会改变。解决问题的方法是:

this.authstate.signout().then(this.router.navigate(['/'])

这两者之间有区别:

authState.subscribe((用户:任意)=>{
如果(用户){
//登录
}
});

onAuthStateChanged((用户:任意)=>{
如果(用户){
//登录
}
});

由于后者将在注销后返回正确的状态…

您能在Stackblitz上重现它吗?authState应在注销时发出一个值。看看这个。登录示例:asdf@asf.comasdfasdf
this.authstate.signout();
this.router.navigate(['/']);
this.authstate.signout().then(this.router.navigate(['/'])