feat: auth race condition & optimize ApolloFactory & too many pageview (#602)
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user