Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions apps/web/src/stores/auth-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ let getSessionFailFirstCall = false;
const syncOnboardingUserMock = mock((_userId: string | null) => {});
const clearOrganizationMock = mock(() => {});
const logoutMock = mock(async () => {});
const deleteBiometricTokenMock = mock(async () => {});

let mockIsNativePlatform = false;
let mockIsBiometricEnabled = false;
let mockBiometricToken: string | null = null;
const installSessionCookiesMock = mock((_token: string) => {});
const retrieveBiometricTokenMock = mock(async () => mockBiometricToken);

mock.module("@/lib/auth/allauth-client.js", () => ({
getSession: async () => {
Expand All @@ -27,18 +34,13 @@ mock.module("@/lib/auth/allauth-client.js", () => ({
logout: logoutMock,
}));

let mockIsNativePlatform = false;
let mockIsBiometricEnabled = false;
let mockBiometricToken: string | null = null;
const installSessionCookiesMock = mock((_token: string) => {});
const retrieveBiometricTokenMock = mock(async () => mockBiometricToken);

mock.module("@/runtime/native-auth.js", () => ({
isNativePlatform: () => mockIsNativePlatform,
installSessionCookies: installSessionCookiesMock,
}));

mock.module("@/runtime/native-biometric.js", () => ({
deleteBiometricToken: deleteBiometricTokenMock,
isBiometricEnabled: () => mockIsBiometricEnabled,
retrieveBiometricToken: retrieveBiometricTokenMock,
}));
Expand Down Expand Up @@ -79,6 +81,8 @@ beforeEach(() => {
syncOnboardingUserMock.mockClear();
clearOrganizationMock.mockClear();
logoutMock.mockClear();
<<<<<<< HEAD
deleteBiometricTokenMock.mockClear();
installSessionCookiesMock.mockClear();
retrieveBiometricTokenMock.mockClear();
resetAuthStore();
Expand Down Expand Up @@ -113,6 +117,14 @@ describe("auth store onboarding flag reconciliation", () => {
});
});

describe("biometric cleanup on logout", () => {
test("logout clears biometric token", async () => {
await useAuthStore.getState().logout();

expect(deleteBiometricTokenMock).toHaveBeenCalled();
});
});

describe("biometric session recovery", () => {
test("initSession falls through to biometric recovery on native when session probe fails", async () => {
mockIsNativePlatform = true;
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/stores/auth-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getSession,
logout as allauthLogout,
} from "@/lib/auth/allauth-client.js";
import { deleteBiometricToken } from "@/runtime/native-biometric.js";
import { syncOnboardingUser } from "@/domains/onboarding/prefs.js";
import { clearOrganization } from "@/stores/organization-store.js";
import { useEventBusStore } from "@/stores/event-bus-store.js";
Expand Down Expand Up @@ -155,6 +156,7 @@ const useAuthStoreBase = create<AuthStore>()((set) => ({
try {
await allauthLogout();
} finally {
void deleteBiometricToken();
syncUserScopedState(null);
set({ isLoggedIn: false, user: null });
broadcastAuthChange();
Expand Down
Loading