|
@@ -30,8 +30,7 @@ const LoadingMask = () => {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
-const AuthModal = () => {
|
|
|
- const { data: user, refetch, isLoading, isError, isFetching } = useQuery({ queryKey: ['auth'], queryFn: queryAuthFn })
|
|
|
+const AuthModal = ({ refetch }: { refetch: () => void }) => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
const intervalId = setInterval(() => {
|
|
@@ -40,12 +39,6 @@ const AuthModal = () => {
|
|
|
return () => clearInterval(intervalId)
|
|
|
}, [refetch])
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (user && !isLoading && !isError && !isFetching) {
|
|
|
- signIn('credentials', { redirect: false, userId: user.userid })
|
|
|
- }
|
|
|
- }, [user, isLoading, isError, isFetching])
|
|
|
-
|
|
|
return (
|
|
|
<dialog className="modal modal-open">
|
|
|
<div className="modal-box relative">
|
|
@@ -58,12 +51,19 @@ const AuthModal = () => {
|
|
|
}
|
|
|
|
|
|
export function AuthProvider({ children }: { children: ReactNode }) {
|
|
|
- const { data: session, status } = useSession()
|
|
|
+ const { status } = useSession()
|
|
|
+ const { data: user, refetch, isLoading, isError, isFetching } = useQuery({ queryKey: ['auth'], queryFn: queryAuthFn })
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (user && !isLoading && !isError && !isFetching) {
|
|
|
+ signIn('credentials', { redirect: false, userId: user.userid })
|
|
|
+ }
|
|
|
+ }, [user, isLoading, isError, isFetching])
|
|
|
|
|
|
- if (status === 'authenticated') {
|
|
|
+ if (status === 'authenticated' && !isLoading && !isError && !isFetching) {
|
|
|
return children
|
|
|
}
|
|
|
return (
|
|
|
- <AuthModal />
|
|
|
+ <AuthModal refetch={refetch} />
|
|
|
)
|
|
|
}
|