加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularFire 2 – Auth.logout()回调

发布时间:2020-12-17 17:02:26 所属栏目:安全 来源:网络整理
导读:我正在尝试注销然后导航到登录URL,但是来自此URL的authguard会阻止已登录的用户查看它,并且因为在解析承诺之前已到达第二行,您需要单击方法事件两次以使其工作. logout(){ this.angularfire.auth.logout(); this.router.navigate(['']); } 当promise被解决时
我正在尝试注销然后导航到登录URL,但是来自此URL的authguard会阻止已登录的用户查看它,并且因为在解析承诺之前已到达第二行,您需要单击方法事件两次以使其工作.

logout(){
    this.angularfire.auth.logout();
    this.router.navigate(['']);
  }

当promise被解决时,有没有办法在回调中实现router.navigate?我已经尝试过then(),但是我的语法不正确或者auth typings有问题……

解决方法

AngularFire2的注销应该以与底层Firebase SDK类似的方式运行.幸运的是,几天前,a PR was merged更改了注销以返回一个承诺 – 所以下一个版本将解决您的问题.

在此之前,您可以收听身份验证更改以确定何时可以导航:

import "rxjs/add/operator/filter";
import "rxjs/add/operator/first";

...

logout(){
  this.angularfire.auth
    // You only want unathenticated states:
    .filter((authState) => !authState)
    // You only want the first unathenticated state:
    .first()
    // You should now be able to navigate:
    .subscribe(() => this.router.navigate(['']));
    // The composed observable completes,so there's no need to unsubscribe.
  this.angularfire.auth.logout();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读