浏览代码

fix: logout

Carson 5 月之前
父节点
当前提交
d234effa9c
共有 2 个文件被更改,包括 8 次插入8 次删除
  1. 3 4
      app/components/providers/AuthProvider.tsx
  2. 5 4
      app/run-agent-flow/components/Header.tsx

+ 3 - 4
app/components/providers/AuthProvider.tsx

@@ -31,7 +31,7 @@ const LoadingMask = () => {
 }
 
 const AuthModal = () => {
-  const { data: user, refetch } = useQuery({ queryKey: ['auth'], queryFn: queryAuthFn })
+  const { data: user, refetch, isLoading, isError, isFetching } = useQuery({ queryKey: ['auth'], queryFn: queryAuthFn })
 
   useEffect(() => {
     const intervalId = setInterval(() => {
@@ -41,10 +41,10 @@ const AuthModal = () => {
   }, [refetch])
 
   useEffect(() => {
-    if (user) {
+    if (user && !isLoading && !isError && !isFetching) {
       signIn('credentials', { redirect: false, userId: user.userid })
     }
-  }, [user])
+  }, [user, isLoading, isError, isFetching])
 
   return (
     <dialog className="modal modal-open">
@@ -60,7 +60,6 @@ const AuthModal = () => {
 export function AuthProvider({ children }: { children: ReactNode }) {
   const { data: session, status } = useSession()
 
-
   if (status === 'authenticated') {
     return children
   }

+ 5 - 4
app/run-agent-flow/components/Header.tsx

@@ -8,17 +8,18 @@ import { useAtomValue } from "jotai";
 import { instantDataAtom, stepsNodesAtom } from "../store";
 import { exportFlowToDocx } from "../export";
 import { BsCloudDownload } from "react-icons/bs";
+import { useQueryClient } from "@tanstack/react-query";
 
 
 export default function Header() {
   const { data: session, status } = useSession()
-
+  const queryClient = useQueryClient()
   const logOut = async () => {
-    const res = await fetch("https://beta.api.cocorobo.cn/api/logout", {
+    await fetch("https://beta.api.cocorobo.cn/api/logout", {
       method: "POST", credentials: 'include'
     });
-    const res1 = await signOut({ redirect: false })
-    debugger
+    queryClient.invalidateQueries({ queryKey: ['auth'] })
+    await signOut({ redirect: false })
   }
 
   return (