feat(web): add login and register pages with auth store
- API client with token refresh interceptor - Auth API functions (login, register, logout, getMe) - Auth store with Zustand persistence - Auth layout with centered card design - Login page with form validation - Register page with company and user data - Environment example file Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
34
apps/web/stores/auth-store.ts
Normal file
34
apps/web/stores/auth-store.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import type { UserInfo } from '@horux/shared';
|
||||
|
||||
interface AuthState {
|
||||
user: UserInfo | null;
|
||||
isAuthenticated: boolean;
|
||||
setUser: (user: UserInfo | null) => void;
|
||||
setTokens: (accessToken: string, refreshToken: string) => void;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
setUser: (user) => set({ user, isAuthenticated: !!user }),
|
||||
setTokens: (accessToken, refreshToken) => {
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
localStorage.setItem('refreshToken', refreshToken);
|
||||
},
|
||||
logout: () => {
|
||||
localStorage.removeItem('accessToken');
|
||||
localStorage.removeItem('refreshToken');
|
||||
set({ user: null, isAuthenticated: false });
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'horux-auth',
|
||||
partialize: (state) => ({ user: state.user, isAuthenticated: state.isAuthenticated }),
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user