From 4fe8f1cb118c67044c9af4cf50a5fca5427ed795 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 20:17:10 +0800 Subject: [PATCH] feat: Add OAuth state parameter handling in sign-in flow --- src/app/(auth)/sign-in/page.tsx | 2 +- src/components/auth/user-auth-form.tsx | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/(auth)/sign-in/page.tsx b/src/app/(auth)/sign-in/page.tsx index d21bb7b..66b45be 100644 --- a/src/app/(auth)/sign-in/page.tsx +++ b/src/app/(auth)/sign-in/page.tsx @@ -48,7 +48,7 @@ export default function LoginPage({ searchParams }: Props) { Q58 Connect - +

By clicking continue, you agree to our{" "} { + oauthState?: string; +} + export function UserAuthForm({ className, + oauthState, ...props -}: React.HTMLAttributes) { +}: UserAuthFormProps) { const [isLoading, setIsLoading] = React.useState(false); const router = useRouter(); const { toast } = useToast(); @@ -23,6 +28,17 @@ export function UserAuthForm({ const signIn = () => { React.startTransition(async () => { try { + // 如果有 OAuth 参数,先保存到 cookie + if (oauthState) { + await fetch("/api/auth/oauth-state", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ state: oauthState }), + }); + } + const response = await fetch("/api/auth/q58", { method: "POST", headers: {