fe5b0e87bd
Must-fix: - Exclude JWT token from Zustand persist (partialize) to prevent localStorage XSS exfiltration — token now lives in memory only - Wire all pages through TanStack Query hooks (usePurchases, useProduct, useProducts, usePriceHistory, useCoupons, usePriceAlerts) with proper loading skeletons and error states - Add mock interceptor in api.ts (VITE_MOCK_API=true) so mock data flows through the same fetch path — single flag to switch to live API Should-fix: - Wire theme toggle to DOM (dark class on <html>) - Fix AccountLinking form inputs (controlled with value/onChange) - Remove unused err in catch blocks (Login, Register) - Bump remaining min-h-10 touch targets to min-h-12 (48px) Build: 128KB initial JS, Recharts 498KB lazy chunk. 5/5 tests pass. Co-Authored-By: Paperclip <noreply@paperclip.ing>
28 lines
763 B
TypeScript
28 lines
763 B
TypeScript
import { create } from 'zustand'
|
|
import { persist } from 'zustand/middleware'
|
|
import type { User } from '../types/api.ts'
|
|
|
|
interface AuthState {
|
|
user: User | null
|
|
token: string | null
|
|
isAuthenticated: boolean
|
|
setAuth: (user: User, token: string) => void
|
|
logout: () => void
|
|
}
|
|
|
|
export const useAuthStore = create<AuthState>()(
|
|
persist(
|
|
(set) => ({
|
|
user: null,
|
|
token: null,
|
|
isAuthenticated: false,
|
|
setAuth: (user, token) => set({ user, token, isAuthenticated: true }),
|
|
logout: () => set({ user: null, token: null, isAuthenticated: false }),
|
|
}),
|
|
{
|
|
name: 'cartsnitch-auth',
|
|
partialize: (state) => ({ user: state.user, isAuthenticated: state.isAuthenticated }),
|
|
},
|
|
),
|
|
)
|