From a40234e6c894bb0627a67a672591f19cba6d5768 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 19:54:25 +0800 Subject: [PATCH] refactor: Consolidate OAuth authorization page and enhance parameter handling --- src/app/(auth)/authorize/metadata.ts | 6 +++++ src/app/(auth)/authorize/page.tsx | 34 +++++++++++++++++-------- src/app/authorize/page.tsx | 38 ---------------------------- 3 files changed, 30 insertions(+), 48 deletions(-) create mode 100644 src/app/(auth)/authorize/metadata.ts delete mode 100644 src/app/authorize/page.tsx diff --git a/src/app/(auth)/authorize/metadata.ts b/src/app/(auth)/authorize/metadata.ts new file mode 100644 index 0000000..f2a0c02 --- /dev/null +++ b/src/app/(auth)/authorize/metadata.ts @@ -0,0 +1,6 @@ +import { Metadata } from "next"; + +export const metadata: Metadata = { + title: "Auth – Q58论坛", + description: "Sign in to your account", +}; diff --git a/src/app/(auth)/authorize/page.tsx b/src/app/(auth)/authorize/page.tsx index 8c18541..685921c 100644 --- a/src/app/(auth)/authorize/page.tsx +++ b/src/app/(auth)/authorize/page.tsx @@ -1,6 +1,8 @@ -import { Suspense } from "react"; -import { Metadata } from "next"; +"use client"; + +import { useEffect } from "react"; import Link from "next/link"; +import { useRouter } from "next/navigation"; import { MessageCircleCode } from "lucide-react"; import { UserAuthorize } from "@/components/auth/user-authorize"; @@ -9,12 +11,26 @@ type Props = { searchParams: { [key: string]: string | string[] | undefined }; }; -export const metadata: Metadata = { - title: `Auth – Q58论坛`, - description: "Sign in to your account", -}; - export default function AuthPage({ searchParams }: Props) { + const router = useRouter(); + + useEffect(() => { + // 检查是否有待处理的 OAuth 请求 + const pendingOAuth = localStorage.getItem("oauth_pending"); + if (pendingOAuth) { + try { + const params = JSON.parse(pendingOAuth); + // 清除存储的 OAuth 参数 + localStorage.removeItem("oauth_pending"); + // 重定向到 OAuth 授权页面 + const searchParams = new URLSearchParams(params); + router.push(`/oauth/authorize?${searchParams.toString()}`); + } catch (error) { + console.error("Failed to process OAuth params:", error); + } + } + }, [router]); + return (
@@ -25,9 +41,7 @@ export default function AuthPage({ searchParams }: Props) {
- - - +

By clicking continue, you agree to our{" "} diff --git a/src/app/authorize/page.tsx b/src/app/authorize/page.tsx deleted file mode 100644 index 5a791b0..0000000 --- a/src/app/authorize/page.tsx +++ /dev/null @@ -1,38 +0,0 @@ -"use client"; - -import { useEffect } from "react"; -import { useRouter } from "next/navigation"; - -export default function AuthorizePage() { - const router = useRouter(); - - useEffect(() => { - // 检查是否有待处理的 OAuth 请求 - const pendingOAuth = localStorage.getItem("oauth_pending"); - if (pendingOAuth) { - try { - const params = JSON.parse(pendingOAuth); - // 清除存储的 OAuth 参数 - localStorage.removeItem("oauth_pending"); - // 重定向到 OAuth 授权页面 - const searchParams = new URLSearchParams(params); - router.push(`/oauth/authorize?${searchParams.toString()}`); - } catch (error) { - console.error("Failed to process OAuth params:", error); - router.push("/dashboard"); - } - } else { - // 如果没有待处理的 OAuth 请求,直接进入仪表板 - router.push("/dashboard"); - } - }, [router]); - - return ( -

-
-
-

正在处理...

-
-
- ); -}