Files
libertas/libertas-frontend/src/hooks/use-auth-storage.ts
Gabriel Kaszewski 252491bd2f feat: refactor frontend routing and authentication
- Changed root div ID from 'root' to 'app' in index.html.
- Updated package.json to include new dependencies for routing and state management.
- Removed App component and replaced it with a router setup in main.tsx.
- Added route definitions for login, about, and index pages.
- Implemented authentication logic using Zustand for state management.
- Created API client with Axios for handling requests and token management.
- Added CORS support in the backend API.
- Updated schema for login requests to use camelCase.
2025-11-16 00:36:30 +01:00

29 lines
713 B
TypeScript

import { create } from 'zustand'
import { createJSONStorage, persist } from 'zustand/middleware'
import type { User } from "@/domain/types"
type AuthState = {
token: string | null
user: User | null
setToken: (token: string, user: User) => void
clearToken: () => void
}
/**
* Global store for authentication state (token and user).
* Persisted to localStorage.
*/
export const useAuthStorage = create<AuthState>()(
persist(
(set) => ({
token: null,
user: null,
setToken: (token, user) => set({ token, user }),
clearToken: () => set({ token: null, user: null }),
}),
{
name: 'auth-storage',
storage: createJSONStorage(() => localStorage),
},
),
)