* Fix auth

* fix lint
This commit is contained in:
Charles Bochet
2023-07-07 05:11:04 +02:00
committed by GitHub
parent f6cf416bb2
commit 11d18cc269
4 changed files with 10 additions and 7 deletions

View File

@ -21,7 +21,6 @@ export function SettingsNavbar() {
const handleLogout = useCallback(() => {
logout();
window.location.href = '/';
}, [logout]);
return (

View File

@ -78,6 +78,7 @@ export function CreateProfile() {
},
},
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
awaitRefetchQueries: true,
});
if (errors || !data?.updateUser) {

View File

@ -55,6 +55,7 @@ export function CreateWorkspace() {
},
},
refetchQueries: [getOperationName(GET_CURRENT_USER) ?? ''],
awaitRefetchQueries: true,
});
if (errors || !data?.updateWorkspace) {

View File

@ -1,20 +1,22 @@
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import { useIsLogged } from '@/auth/hooks/useIsLogged';
import { currentUserState } from '@/auth/states/currentUserState';
import { useGetCurrentUserQuery } from '~/generated/graphql';
export function UserProvider({ children }: React.PropsWithChildren) {
const [currentUser, setCurrentUser] = useRecoilState(currentUserState);
const isLoggedIn = useIsLogged();
const [, setCurrentUser] = useRecoilState(currentUserState);
const { data, loading } = useGetCurrentUserQuery();
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
if (!loading) {
setIsLoading(false);
}
if (data?.currentUser) {
setCurrentUser(data?.currentUser);
}
}, [setCurrentUser, data]);
}, [setCurrentUser, data, isLoading, loading]);
return loading || (isLoggedIn && !currentUser) ? <></> : <>{children}</>;
return isLoading ? <></> : <>{children}</>;
}