fix(auth): preserve intentional logout across browser return
Keep a bounded per-tab logout intent and broadcast it to already open tabs so back navigation after a normal logout is not mistaken for renewal failure. Preserve real refresh and session expiry signals, and keep IdP navigation reachable when local cleanup fails.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
clearIntentionalLogout,
|
||||
markIntentionalLogout,
|
||||
} from "@/lib/logoutIntent";
|
||||
|
||||
import { useAuthStore } from "./authStore";
|
||||
|
||||
describe("authStore intentional logout boundary", () => {
|
||||
beforeEach(() => {
|
||||
clearIntentionalLogout();
|
||||
useAuthStore.setState({
|
||||
accessToken: "access-token",
|
||||
sessionExpired: false,
|
||||
sessionExpiryReason: null,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clearIntentionalLogout();
|
||||
});
|
||||
|
||||
it("ignores late expiry signals after an intentional logout", () => {
|
||||
markIntentionalLogout();
|
||||
|
||||
useAuthStore.getState().markSessionExpired("unauthorized");
|
||||
|
||||
expect(useAuthStore.getState()).toMatchObject({
|
||||
accessToken: null,
|
||||
sessionExpired: false,
|
||||
sessionExpiryReason: null,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps real refresh failures visible after an intentional logout", () => {
|
||||
markIntentionalLogout();
|
||||
|
||||
useAuthStore.getState().markSessionExpired("refresh_failed");
|
||||
|
||||
expect(useAuthStore.getState()).toMatchObject({
|
||||
accessToken: null,
|
||||
sessionExpired: true,
|
||||
sessionExpiryReason: "refresh_failed",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user