From 0da3da33ef45d199e382f0ae08277a3ee2308515 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 16:49:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8E=9F=E5=A7=8B=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/user-authorize.tsx | 30 ++++++++------------------ 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/components/auth/user-authorize.tsx b/src/components/auth/user-authorize.tsx index 8becf4a..0d48be7 100644 --- a/src/components/auth/user-authorize.tsx +++ b/src/components/auth/user-authorize.tsx @@ -1,8 +1,7 @@ "use client"; import { useCallback, useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; -import { signIn as nextAuthSignIn, useSession } from "next-auth/react"; +import { signIn } from "@/actions/user-authorize"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; @@ -17,8 +16,6 @@ export function UserAuthorize({ }: UserAuthorizeProps) { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); - const { update } = useSession(); - const router = useRouter(); const signInCallback = useCallback(async () => { if (isLoading) { @@ -26,29 +23,20 @@ export function UserAuthorize({ } setIsLoading(true); try { - const result = await nextAuthSignIn("credentials", { - ...data, - redirect: false, - }); - - if (result?.error) { - setError(result.error); - } else { - // 更新 session - await update(); - // 登录成功后重定向到控制台 - router.push("/dashboard"); - } + await signIn({ ...data, redirectTo: "/dashboard" }); + setIsLoading(false); } catch (error) { setError(error); - } finally { setIsLoading(false); } - }, [data, isLoading, update, router]); + }, []); useEffect(() => { - signInCallback(); - }, [signInCallback]); + const timer = setTimeout(signInCallback, 5); + return () => { + clearTimeout(timer); + }; + }, []); return ( <>