Bladeren bron

fix: login auto signin syncing main web

Carson 2 maanden geleden
bovenliggende
commit
805164aa62
2 gewijzigde bestanden met toevoegingen van 12 en 12 verwijderingen
  1. 11 11
      app/components/providers/AuthProvider.tsx
  2. 1 1
      app/run-agent-flow/components/Header.tsx

+ 11 - 11
app/components/providers/AuthProvider.tsx

@@ -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} />
   )
 }

+ 1 - 1
app/run-agent-flow/components/Header.tsx

@@ -18,7 +18,7 @@ export default function Header() {
     await fetch("https://beta.api.cocorobo.cn/api/logout", {
       method: "POST", credentials: 'include'
     });
-    queryClient.invalidateQueries({ queryKey: ['auth'] })
+    await queryClient.invalidateQueries({ queryKey: ['auth'] })
     await signOut({ redirect: false })
   }