mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
- Added a new auth store using Zustand to manage authentication state, including `authChecked` and `isAuthenticated`. - Updated `LoginView` to set authentication state upon successful login and navigate based on setup completion. - Enhanced `RootLayoutContent` to enforce routing rules based on authentication status, redirecting users to login or setup as necessary. - Improved error handling and loading states during authentication checks.
30 lines
757 B
TypeScript
30 lines
757 B
TypeScript
import { create } from 'zustand';
|
|
|
|
interface AuthState {
|
|
/** Whether we've attempted to determine auth status for this page load */
|
|
authChecked: boolean;
|
|
/** Whether the user is currently authenticated (web mode: valid session cookie) */
|
|
isAuthenticated: boolean;
|
|
}
|
|
|
|
interface AuthActions {
|
|
setAuthState: (state: Partial<AuthState>) => void;
|
|
resetAuth: () => void;
|
|
}
|
|
|
|
const initialState: AuthState = {
|
|
authChecked: false,
|
|
isAuthenticated: false,
|
|
};
|
|
|
|
/**
|
|
* Web authentication state.
|
|
*
|
|
* Intentionally NOT persisted: source of truth is the server session cookie.
|
|
*/
|
|
export const useAuthStore = create<AuthState & AuthActions>((set) => ({
|
|
...initialState,
|
|
setAuthState: (state) => set(state),
|
|
resetAuth: () => set(initialState),
|
|
}));
|