From 465bf1dff5c9c0efa0e5cb945e6acb1769686fa3 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 21:56:54 +0800 Subject: [PATCH] feat: Add UserAuthForm to authorize page and enhance SSO/OAuth login handling --- src/app/(auth)/authorize/page.tsx | 4 ++++ src/components/auth/user-auth-form.tsx | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/app/(auth)/authorize/page.tsx b/src/app/(auth)/authorize/page.tsx index 1e839b2..5cb738f 100644 --- a/src/app/(auth)/authorize/page.tsx +++ b/src/app/(auth)/authorize/page.tsx @@ -5,6 +5,8 @@ import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { MessageCircleCode } from "lucide-react"; +import { UserAuthForm } from "@/components/auth/user-auth-form"; + export default function AuthPage() { const router = useRouter(); const searchParams = useSearchParams(); @@ -12,6 +14,7 @@ export default function AuthPage() { useEffect(() => { // 如果有 OAuth 参数,重定向回 /oauth/authorize if (searchParams.has("response_type") && searchParams.has("client_id")) { + console.log("检测到 OAuth 参数,准备重定向到 /oauth/authorize"); router.replace(`/oauth/authorize?${searchParams.toString()}`); return; } @@ -26,6 +29,7 @@ export default function AuthPage() { Q58论坛 +

By clicking continue, you agree to our{" "} = {}; + // 如果有 SSO 参数,使用 credentials provider 登录 + if (searchParams.has("sso") && searchParams.has("sig")) { + console.log("检测到 SSO 参数,使用 credentials provider 登录"); + const result = await signIn("credentials", { + sso: searchParams.get("sso"), + sig: searchParams.get("sig"), + redirect: false, + }); - // 如果有 OAuth 参数,作为 return_url 传递 + if (result?.error) { + throw new Error(result.error); + } + + // 登录成功后刷新页面 + router.refresh(); + return; + } + + // 如果有 OAuth 参数,发起 SSO 登录 + const body: Record = {}; if (searchParams.has("response_type") && searchParams.has("client_id")) { body.return_url = `/oauth/authorize?${searchParams.toString()}`; console.log("正在处理 OAuth 登录,return_url:", body.return_url); @@ -70,7 +88,7 @@ export function UserAuthForm({ className={cn(buttonVariants({ variant: "outline" }))} onClick={() => { setIsLoading(true); - signIn(); + handleSignIn(); }} disabled={isLoading} >