【问题标题】:Angular replays http calls when refresh token changesAngular 在刷新令牌更改时重播 http 调用
【发布时间】:2019-06-13 16:42:06
【问题描述】:

我在Angular v6 中遇到了一个奇怪的行为。可能我在处理订阅时遗漏了一些重要的东西。

每当刷新令牌过期(经过一段空闲时间而不使用应用程序),应用程序replays 之前的所有 http 事件。

以下是我重现该问题的方法。

  1. 登录到我的 Angular 应用并进行一些 N http 调用 (GET, POST and DELETE)
  2. firebaseLocalStorage indexedDB 中删除firebase refresh auth token

第 2 步触发并重放我在第 1 步中进行的所有 http 调用。

但它不应该重播所有过去的 http 事件。可能是什么原因?

我的http拦截器代码在https://gist.github.com/kumar-muthu/87c1404d3da48702739183e8d2c6e7d5

注意:我不会取消订阅 http observables,因为我假设 angular httpclient 会在收到 http 响应后关闭订阅。

【问题讨论】:

  • 如果您从本地存储中删除 firebase 刷新身份验证令牌,您怎么能期望不会失败?可能我无法理解你的问题
  • @Simonare 编辑了它。核心问题是http调用的自动重放。我想知道为什么会这样。

标签: angular rxjs firebase-authentication


【解决方案1】:

问题出在拦截器上。我不仅订阅了最新的令牌,还订阅了令牌。因此,每次令牌更改时,所有先前的 http 请求都会再次重播。

https://gist.github.com/kumar-muthu/87c1404d3da48702739183e8d2c6e7d5#file-so_angular_http_inteceptor-ts-L47

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2017-12-31
    • 2018-06-12
    • 1970-01-01
    • 2021-05-01
    • 2021-04-06
    • 2017-10-11
    相关资源
    最近更新 更多