Blame · Line-by-line history
authStore.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 5c83ccc | 1 | import { create } from 'zustand'; |
| 2 | ||
| 3 | export interface AuthUser { | |
| 4 | id: number; | |
| 5 | username: string; | |
| 6 | email: string; | |
| 7 | avatarUrl: string | null; | |
| 8 | bio: string | null; | |
| 9 | createdAt: string; | |
| 10 | } | |
| 11 | ||
| 12 | interface AuthState { | |
| 13 | isAuthenticated: boolean; | |
| 14 | user: AuthUser | null; | |
| 15 | token: string | null; | |
| 16 | setAuth: (user: AuthUser, token: string) => void; | |
| 17 | clearAuth: () => void; | |
| 18 | } | |
| 19 | ||
| 20 | export const useAuthStore = create<AuthState>((set) => ({ | |
| 21 | isAuthenticated: false, | |
| 22 | user: null, | |
| 23 | token: null, | |
| 24 | setAuth: (user: AuthUser, token: string) => | |
| 25 | set({ isAuthenticated: true, user, token }), | |
| 26 | clearAuth: () => | |
| 27 | set({ isAuthenticated: false, user: null, token: null }), | |
| 28 | })); |