mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
feat: Add OAuth state parameter handling in sign-in flow
This commit is contained in:
parent
03107936ad
commit
4fe8f1cb11
@ -48,7 +48,7 @@ export default function LoginPage({ searchParams }: Props) {
|
|||||||
<span style={{ fontFamily: "Bahamas Bold" }}>Q58 Connect</span>
|
<span style={{ fontFamily: "Bahamas Bold" }}>Q58 Connect</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<UserAuthForm />
|
<UserAuthForm oauthState={searchParams.state} />
|
||||||
<p className="px-8 text-center text-sm text-muted-foreground">
|
<p className="px-8 text-center text-sm text-muted-foreground">
|
||||||
By clicking continue, you agree to our{" "}
|
By clicking continue, you agree to our{" "}
|
||||||
<Link
|
<Link
|
||||||
|
@ -12,10 +12,15 @@ interface DiscourseData {
|
|||||||
sso_url: string;
|
sso_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||||
|
oauthState?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export function UserAuthForm({
|
export function UserAuthForm({
|
||||||
className,
|
className,
|
||||||
|
oauthState,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: UserAuthFormProps) {
|
||||||
const [isLoading, setIsLoading] = React.useState<boolean>(false);
|
const [isLoading, setIsLoading] = React.useState<boolean>(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@ -23,6 +28,17 @@ export function UserAuthForm({
|
|||||||
const signIn = () => {
|
const signIn = () => {
|
||||||
React.startTransition(async () => {
|
React.startTransition(async () => {
|
||||||
try {
|
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", {
|
const response = await fetch("/api/auth/q58", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user