Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit c6094fd

Browse files
added catch
1 parent fcee348 commit c6094fd

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/utils/auth.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createRoot, createSignal } from 'solid-js'
33

44
type INITIAL_STATE = { state: 'INITIAL' }
55
type LOADING_STATE = { state: 'LOADING' }
6-
export type LOADED_STATE = { state: 'LOADED'; data: Session | null }
6+
export type LOADED_STATE = { state: 'LOADED'; data: Session | null; reason?: string }
77

88
type STATE = INITIAL_STATE | LOADING_STATE | LOADED_STATE
99

@@ -17,12 +17,20 @@ export const useSession = () => {
1717
const session = currentSession()
1818
if (session.state === 'INITIAL') {
1919
setCurrentSession({ state: 'LOADING' })
20-
fetch('/api/session').then(async (response) =>
21-
setCurrentSession({
22-
state: 'LOADED',
23-
data: await response.json(),
24-
}),
25-
)
20+
fetch('/api/session')
21+
.then(async (response) =>
22+
setCurrentSession({
23+
state: 'LOADED',
24+
data: await response.json(),
25+
}),
26+
)
27+
.catch((e) =>
28+
setCurrentSession({
29+
state: 'LOADED',
30+
data: null,
31+
reason: e?.toString(),
32+
}),
33+
)
2634
}
2735

2836
return currentSession

0 commit comments

Comments
 (0)