Files
leocrm/frontend/src/hooks/useAuth.ts
T

23 lines
549 B
TypeScript
Raw Normal View History

import { useEffect } from 'react';
import { useAuthStore } from '@/store/authStore';
import { useCurrentUser } from '@/api/hooks';
export function useAuth() {
const store = useAuthStore();
const { data, isLoading, isError } = useCurrentUser();
useEffect(() => {
if (isError) {
store.setAuthenticated(false);
store.setUser(null);
}
}, [isError, store]);
return {
user: store.user,
isAuthenticated: store.isAuthenticated,
isLoading: isLoading && !store.user,
currentTenant: store.currentTenant,
};
}