38 lines
753 B
TypeScript
38 lines
753 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
import {
|
|
useClearSessionCookieMutation,
|
|
useFindProfileQuery,
|
|
} from '@/graphql/generated/output';
|
|
|
|
import { useAuth } from './useAuth';
|
|
|
|
export function useCurrent() {
|
|
const { isAuthenticated, exit } = useAuth();
|
|
|
|
const {
|
|
data, loading, refetch, error,
|
|
} = useFindProfileQuery({
|
|
skip: !isAuthenticated,
|
|
});
|
|
const [clear] = useClearSessionCookieMutation();
|
|
|
|
useEffect(() => {
|
|
if (error) {
|
|
console.log('error', error);
|
|
if (isAuthenticated) {
|
|
console.log('CLEAR');
|
|
void clear();
|
|
}
|
|
console.log('exit');
|
|
exit();
|
|
}
|
|
}, [isAuthenticated, exit, clear]);
|
|
|
|
return {
|
|
user: data?.findProfile,
|
|
isLoadingProfile: loading,
|
|
refetch,
|
|
};
|
|
}
|