Skip to content
File

Blob: src/client/hooks/use-auth.ts

typescript23 lines
1import { useCallback } from "react";
2import { useAuthStore, selectIsAuthenticated } from "@/client/stores/auth-store";
3import { resetWorkspaceLocalOwner } from "@/client/stores/bootstrap";
4import { api } from "@/client/lib/api";
5 
6export function useAuth() {
7 const isAuthenticated = useAuthStore(selectIsAuthenticated);
8 const user = useAuthStore((s) => s.user);
9 const clearAuth = useAuthStore((s) => s.clearAuth);
10 
11 const logout = useCallback(async () => {
12 try {
13 await api.auth.logout();
14 } catch {
15 // Ignore errors - clear local state regardless
16 }
17 clearAuth();
18 await resetWorkspaceLocalOwner();
19 }, [clearAuth]);
20 
21 return { isAuthenticated, user, logout };
22}