@fakel/rest-admin
Version:
An application that makes it easier to work with your API
29 lines (23 loc) • 670 B
text/typescript
import { useEffect } from 'react';
import { useAuthProviderStore } from './useAuthProviderStore';
import { useAuthStore } from './useAuthStore';
export const useCheckAuth = () => {
const authProviderStore = useAuthProviderStore();
const authStore = useAuthStore();
const { authProvider } = authProviderStore;
const checkAuth = () => {
authProvider
.checkAuth()
.then((isAuthorized) => {
authStore.setIsAuth(isAuthorized);
})
.catch((error) => {
authStore.setIsAuth(false);
console.error(error);
});
};
useEffect(() => {
checkAuth();
}, []);
return { isAuthorized: authStore.isAuth };
};