refactor: Simplify OAuth authentication flow and update branding

- 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
This commit is contained in:
wood chen 2025-02-21 13:32:51 +08:00
parent a85c15381a
commit f9521d9afb
2 changed files with 8 additions and 16 deletions

View File

@ -53,7 +53,7 @@ export function UserAuthForm({
) : (
<MessageCircleCode className="mr-2 size-4" />
)}{" "}
Q58论坛
Q58
</button>
</div>
);

View File

@ -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<HTMLDivElement> {
data: Record<string, any>;
@ -14,6 +16,7 @@ export function UserAuthorize({
}: UserAuthorizeProps) {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [error, setError] = useState<Error | unknown>(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);