From 0ef9ae79037a1cd141ab8019b709fd8b71f1bd28 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 16:40:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8E=88=E6=9D=83=E7=BB=84=E4=BB=B6=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/auth/user-authorize.tsx | 93 +++++++++++--------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/src/components/auth/user-authorize.tsx b/src/components/auth/user-authorize.tsx index 09ec2b5..5530211 100644 --- a/src/components/auth/user-authorize.tsx +++ b/src/components/auth/user-authorize.tsx @@ -1,9 +1,7 @@ "use client"; import { useCallback, useEffect, useState } from "react"; -import { useRouter } from "next/navigation"; import { signIn } from "@/actions/user-authorize"; -import { useSession } from "next-auth/react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; @@ -18,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) { @@ -27,26 +23,13 @@ export function UserAuthorize({ } setIsLoading(true); try { - // 从 URL 中获取 sso 和 sig 参数 - const url = new URL(window.location.href); - const sso = url.searchParams.get("sso"); - const sig = url.searchParams.get("sig"); - - if (!sso || !sig) { - throw new Error("缺少必要的认证参数"); - } - - // 直接调用signIn,它会处理SSO回调中的return_sso_url - await signIn({ sso, sig }); - // 更新session状态 - await update(); + await signIn(data); setIsLoading(false); } catch (error) { - console.error("登录过程出错:", error); setError(error); setIsLoading(false); } - }, [isLoading, update]); + }, [data, isLoading]); useEffect(() => { const timer = setTimeout(signInCallback, 5); @@ -55,41 +38,43 @@ export function UserAuthorize({ }; }, [signInCallback]); - if (error) { - return ( - - -
-
-
- - 授权失败 - -
- -

- {error instanceof Error - ? error.message - : "登录异常,授权失败!请稍后重试。"} -

-
-
- ); - } - return ( - - -
-
-
- 正在处理授权 -
- -

- {isLoading ? "请稍候,我们正在处理您的授权请求" : "正在跳转..."} -

-
-
+ <> + {error ? ( + + +
+
+
+ + 授权失败 + +
+ +

+ {error instanceof Error + ? error.message + : "登录异常,授权失败!请稍后重试。"} +

+
+
+ ) : ( + + +
+
+
+ + 正在处理授权 + +
+ +

+ {isLoading ? "请稍候,我们正在处理您的授权请求" : "正在跳转..."} +

+
+
+ )} + ); }