Skip to content

Commit 5b4ff4a

Browse files
committed
feat: Refactor auth modal store to include error handling and simplify usage in hooks
1 parent bde2db3 commit 5b4ff4a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/features/auth/hooks/useAuth.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { trackUserDisconnect } from 'src/lib/analytics'
44
import { firebaseAuth } from 'src/lib/firebase'
55

66
export const useAuth = () => {
7-
const { isAuthModalOpen, openAuthModal, closeAuthModal } = AuthModalStore()
7+
const authModalStore = AuthModalStore()
88
const authStore = AuthStore()
99
const { user, providerId, initState, clear } = authStore
1010

@@ -18,12 +18,10 @@ export const useAuth = () => {
1818
}
1919

2020
return {
21-
openAuthModal,
22-
closeAuthModal,
21+
...authModalStore,
2322
initState,
2423
isConnected,
2524
logout,
26-
isAuthModalOpen,
2725
user,
2826
providerId,
2927
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import { create } from 'zustand'
22

3+
type AuthError = {
4+
message: string
5+
retry?: {
6+
label: string
7+
} | null
8+
}
39
interface AuthModalState {
410
isAuthModalOpen: boolean
11+
authError: AuthError | null
512
openAuthModal: () => void
613
closeAuthModal: () => void
14+
setAuthError: (error: AuthError | null) => void
715
}
816

917
export const AuthModalStore = create<AuthModalState>((set) => ({
1018
isAuthModalOpen: false,
19+
authError: null,
20+
setAuthError: (error) => set({ authError: error }),
1121
openAuthModal: () => set({ isAuthModalOpen: true }),
1222
closeAuthModal: () => set({ isAuthModalOpen: false }),
1323
}))

0 commit comments

Comments
 (0)