From f9521d9afb3fa116aeed980b87ce32f3224b392a Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 13:32:51 +0800 Subject: [PATCH] refactor: Simplify OAuth authentication flow and update branding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove complex OAuth parameter handling in UserAuthorize component - Streamline sign-in process with direct dashboard redirect - Update UserAuthForm to use simplified branding (Q58 instead of Q58论坛) - Add session update after successful authentication --- src/components/auth/user-auth-form.tsx | 2 +- src/components/auth/user-authorize.tsx | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/components/auth/user-auth-form.tsx b/src/components/auth/user-auth-form.tsx index de3ad1d..2150ab9 100644 --- a/src/components/auth/user-auth-form.tsx +++ b/src/components/auth/user-auth-form.tsx @@ -53,7 +53,7 @@ export function UserAuthForm({ ) : ( )}{" "} - Q58论坛 + Q58 ); diff --git a/src/components/auth/user-authorize.tsx b/src/components/auth/user-authorize.tsx index ead469a..dd565c6 100644 --- a/src/components/auth/user-authorize.tsx +++ b/src/components/auth/user-authorize.tsx @@ -1,7 +1,9 @@ "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"; interface UserAuthorizeProps extends React.HTMLAttributes { data: Record; @@ -14,6 +16,7 @@ export function UserAuthorize({ }: UserAuthorizeProps) { const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); + const { update } = useSession(); const signInCallback = useCallback(async () => { if (isLoading) { @@ -21,26 +24,15 @@ export function UserAuthorize({ } setIsLoading(true); try { - // 检查是否有 OAuth 参数 - const searchParams = new URLSearchParams(data); - const sso = searchParams.get("sso"); - const sig = searchParams.get("sig"); - const oauth = searchParams.get("oauth"); - - let redirectTo = "/dashboard"; - if (sso && sig && oauth) { - // 如果是从Q58论坛回调,使用原始的OAuth参数 - const oauthParams = new URLSearchParams(atob(oauth)); - redirectTo = `/oauth/authorize?${oauthParams.toString()}`; - } - - await signIn({ ...data, redirectTo }); + await signIn({ ...data, redirectTo: "/dashboard" }); + // 更新 session + await update(); setIsLoading(false); } catch (error) { setError(error); setIsLoading(false); } - }, [data, isLoading]); + }, [data, isLoading, update]); useEffect(() => { const timer = setTimeout(signInCallback, 5);