Skip to content

Commit c5b8901

Browse files
msujawsclaude
andcommitted
fix(auth): load persisted API key on app mount
The loadApiKey action existed but was never called on startup, causing users to re-enter their API key after each page refresh. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent eec208f commit c5b8901

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/App.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach } from 'vitest'
1+
import { describe, it, expect, beforeEach, vi } from 'vitest'
22
import { render, screen } from '@testing-library/react'
33
import App from './App'
44
import { useStore } from './store'
@@ -20,6 +20,15 @@ describe('App', () => {
2020
})
2121

2222
describe('without API key', () => {
23+
it('should call loadApiKey on mount to restore persisted key', () => {
24+
const loadApiKey = vi.fn()
25+
useStore.setState({ loadApiKey })
26+
27+
render(<App />)
28+
29+
expect(loadApiKey).toHaveBeenCalledOnce()
30+
})
31+
2332
it('should render the app title', () => {
2433
render(<App />)
2534

src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ function App() {
1515

1616
// Auth state
1717
const apiKey = useStore((state) => state.apiKey)
18+
const loadApiKey = useStore((state) => state.loadApiKey)
19+
20+
// Load persisted API key on mount
21+
useEffect(() => {
22+
void loadApiKey()
23+
}, [loadApiKey])
1824

1925
// Bugs state
2026
const bugs = useStore((state) => state.bugs)

0 commit comments

Comments
 (0)