From 68c41839ec7268a401566cbb32e46f7dd150ac64 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 30 Aug 2025 22:46:38 -0400 Subject: [PATCH] fix: Ensure logout clears both Firebase auth and API key (#5274) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Ensure logout clears both Firebase auth and API key When logging out via the avatar dropdown, the logout function was only clearing Firebase authentication but not the stored API key. This could leave users partially authenticated with their API key still active. Updated CurrentUserPopover to use handleSignOut from useCurrentUser composable, which properly handles both authentication methods: - Clears API key if logged in with API key - Signs out Firebase if logged in with Firebase This ensures complete logout regardless of authentication method. Fixes #5261 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * test: Update CurrentUserPopover tests to match new logout implementation Updated test mocks to include handleSignOut from useCurrentUser composable and adjusted test expectations to verify handleSignOut is called instead of the direct logout method. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- src/components/topbar/CurrentUserPopover.spec.ts | 8 +++++--- src/components/topbar/CurrentUserPopover.vue | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/topbar/CurrentUserPopover.spec.ts b/src/components/topbar/CurrentUserPopover.spec.ts index c4e34ae79..9929d316a 100644 --- a/src/components/topbar/CurrentUserPopover.spec.ts +++ b/src/components/topbar/CurrentUserPopover.spec.ts @@ -41,11 +41,13 @@ afterAll(() => { }) // Mock the useCurrentUser composable +const mockHandleSignOut = vi.fn() vi.mock('@/composables/auth/useCurrentUser', () => ({ useCurrentUser: vi.fn(() => ({ userPhotoUrl: 'https://example.com/avatar.jpg', userDisplayName: 'Test User', - userEmail: 'test@example.com' + userEmail: 'test@example.com', + handleSignOut: mockHandleSignOut })) })) @@ -155,8 +157,8 @@ describe('CurrentUserPopover', () => { // Click the logout button await logoutButton.trigger('click') - // Verify logout was called - expect(mockLogout).toHaveBeenCalled() + // Verify handleSignOut was called + expect(mockHandleSignOut).toHaveBeenCalled() // Verify close event was emitted expect(wrapper.emitted('close')).toBeTruthy() diff --git a/src/components/topbar/CurrentUserPopover.vue b/src/components/topbar/CurrentUserPopover.vue index e74a927c8..812341c2f 100644 --- a/src/components/topbar/CurrentUserPopover.vue +++ b/src/components/topbar/CurrentUserPopover.vue @@ -88,7 +88,8 @@ const emit = defineEmits<{ close: [] }>() -const { userDisplayName, userEmail, userPhotoUrl } = useCurrentUser() +const { userDisplayName, userEmail, userPhotoUrl, handleSignOut } = + useCurrentUser() const authActions = useFirebaseAuthActions() const dialogService = useDialogService() @@ -103,7 +104,7 @@ const handleTopUp = () => { } const handleLogout = async () => { - await authActions.logout() + await handleSignOut() emit('close') }