mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 14:01:55 +08:00
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:
parent
a85c15381a
commit
f9521d9afb
@ -53,7 +53,7 @@ export function UserAuthForm({
|
|||||||
) : (
|
) : (
|
||||||
<MessageCircleCode className="mr-2 size-4" />
|
<MessageCircleCode className="mr-2 size-4" />
|
||||||
)}{" "}
|
)}{" "}
|
||||||
Q58论坛
|
Q58
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import { signIn } from "@/actions/user-authorize";
|
import { signIn } from "@/actions/user-authorize";
|
||||||
|
import { useSession } from "next-auth/react";
|
||||||
|
|
||||||
interface UserAuthorizeProps extends React.HTMLAttributes<HTMLDivElement> {
|
interface UserAuthorizeProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
data: Record<string, any>;
|
data: Record<string, any>;
|
||||||
@ -14,6 +16,7 @@ export function UserAuthorize({
|
|||||||
}: UserAuthorizeProps) {
|
}: UserAuthorizeProps) {
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [error, setError] = useState<Error | unknown>(null);
|
const [error, setError] = useState<Error | unknown>(null);
|
||||||
|
const { update } = useSession();
|
||||||
|
|
||||||
const signInCallback = useCallback(async () => {
|
const signInCallback = useCallback(async () => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@ -21,26 +24,15 @@ export function UserAuthorize({
|
|||||||
}
|
}
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
// 检查是否有 OAuth 参数
|
await signIn({ ...data, redirectTo: "/dashboard" });
|
||||||
const searchParams = new URLSearchParams(data);
|
// 更新 session
|
||||||
const sso = searchParams.get("sso");
|
await update();
|
||||||
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 });
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error);
|
setError(error);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [data, isLoading]);
|
}, [data, isLoading, update]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(signInCallback, 5);
|
const timer = setTimeout(signInCallback, 5);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user