feat: Add OAuth state parameter handling in sign-in flow

This commit is contained in:
wood chen 2025-02-21 20:17:10 +08:00
parent 03107936ad
commit 4fe8f1cb11
2 changed files with 18 additions and 2 deletions

View File

@ -48,7 +48,7 @@ export default function LoginPage({ searchParams }: Props) {
<span style={{ fontFamily: "Bahamas Bold" }}>Q58 Connect</span>
</div>
</div>
<UserAuthForm />
<UserAuthForm oauthState={searchParams.state} />
<p className="px-8 text-center text-sm text-muted-foreground">
By clicking continue, you agree to our{" "}
<Link

View File

@ -12,10 +12,15 @@ interface DiscourseData {
sso_url: string;
}
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {
oauthState?: string;
}
export function UserAuthForm({
className,
oauthState,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
}: UserAuthFormProps) {
const [isLoading, setIsLoading] = React.useState<boolean>(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: {