Преглед изворни кода

fix: login auto signin syncing main web

Carson пре 2 месеци
родитељ
комит
805164aa62
2 измењених фајлова са 12 додато и 12 уклоњено
  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 })
   }