diff --git a/chatdesk-ui/app/[locale]/[workspaceid]/layout.tsx b/chatdesk-ui/app/[locale]/[workspaceid]/layout.tsx index f3bd88e..7149c4f 100644 --- a/chatdesk-ui/app/[locale]/[workspaceid]/layout.tsx +++ b/chatdesk-ui/app/[locale]/[workspaceid]/layout.tsx @@ -70,6 +70,8 @@ export default function WorkspaceLayout({ children }: WorkspaceLayoutProps) { } = useContext(ChatbotUIContext) const [loading, setLoading] = useState(true) + const [redirected, setRedirected] = useState(false) // 防止重复跳转 + useEffect(() => { @@ -77,14 +79,16 @@ export default function WorkspaceLayout({ children }: WorkspaceLayoutProps) { //const supabaseClient = await supabase(); // Await the client creation const session = (await supabase.auth.getSession()).data.session - if (!session) { + //if (!session) { + if (!session && !redirected) { // 跳转到带有 locale 的登录页面 + setRedirected(true) // 设置标志,避免跳转重复 return router.push(`/${locale}/login`) } else { await fetchWorkspaceData(workspaceId) } })() - }, []) + }, [workspaceId, redirected]) useEffect(() => {