Question
ngrx token refresh effect: how to avoid infinite retry loops when backend is down
Cig Dey
0 reputation · 28 Jul 2023, 02:39 UTC
92.8K views0
Problem with automatic token refresh
In many ngrx applications the AuthEffects intercept a RefreshToken action, call the backend, and dispatch a new SetToken action. When the backend is unreachable, the effect may keep re‑dispatching RefreshToken endlessly because no retry limit is defined.
Additionally, the meta‑reducer that clears the store on Logout must decide which slices to wipe and which to keep. The library offers no guidance, leading to inconsistent preservation of UI state such as theme or layout.
Unresolved questions
- What is the recommended pattern for limiting retry attempts in a token‑refresh effect, and how should the failure threshold be exposed to the application?
- Which state slices should be preserved during a logout to maintain a least‑privilege posture without unintentionally retaining sensitive data?
- How can an effect safely inspect a token’s expiry from
localStorageand trigger a single logout action without race conditions across multiple tabs?