feat: auth race condition & optimize ApolloFactory & too many pageview (#602)

This commit is contained in:
Jérémy M
2023-07-11 19:50:25 +02:00
committed by GitHub
parent 55576cb638
commit 718ad721cf
12 changed files with 69 additions and 44 deletions

View File

@ -1,14 +1,20 @@
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 [, setCurrentUser] = useRecoilState(currentUserState);
const { data, loading } = useGetCurrentUserQuery();
const [isLoading, setIsLoading] = useState(true);
const isLogged = useIsLogged();
const { data, loading } = useGetCurrentUserQuery({
skip: !isLogged,
});
useEffect(() => {
if (!loading) {
setIsLoading(false);