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.
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
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",
|
|
});
|
|
});
|
|
});
|