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 ? "请稍候,我们正在处理您的授权请求" : "正在跳转..."} +

+
+
+ )} + ); }