fix: Ensure logout clears both Firebase auth and API key (#5274)

* 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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Benjamin Lu
2025-08-30 22:46:38 -04:00
committed by GitHub
parent 2e72988ef8
commit 68c41839ec
2 changed files with 8 additions and 5 deletions

View File

@@ -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()

View File

@@ -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')
}