mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-19 06:21:55 +08:00
fix: Improve SSO authentication form submission with dynamic parameter extraction
This commit is contained in:
parent
2c94af2b91
commit
849265a26f
@ -66,10 +66,30 @@ export function UserAuthForm({
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log("收到 SSO URL:", data.sso_url);
|
console.log("收到 SSO URL:", data.sso_url);
|
||||||
|
|
||||||
|
// 解析 SSO URL 并提取参数
|
||||||
|
const ssoUrl = new URL(data.sso_url);
|
||||||
|
const sso = ssoUrl.searchParams.get("sso");
|
||||||
|
const sig = ssoUrl.searchParams.get("sig");
|
||||||
|
|
||||||
// 使用表单提交方式跳转
|
// 使用表单提交方式跳转
|
||||||
if (formRef.current) {
|
if (formRef.current && sso && sig) {
|
||||||
formRef.current.action = data.sso_url;
|
const form = formRef.current;
|
||||||
formRef.current.submit();
|
// 创建隐藏的输入字段
|
||||||
|
const ssoInput = document.createElement("input");
|
||||||
|
ssoInput.type = "hidden";
|
||||||
|
ssoInput.name = "sso";
|
||||||
|
ssoInput.value = sso;
|
||||||
|
form.appendChild(ssoInput);
|
||||||
|
|
||||||
|
const sigInput = document.createElement("input");
|
||||||
|
sigInput.type = "hidden";
|
||||||
|
sigInput.name = "sig";
|
||||||
|
sigInput.value = sig;
|
||||||
|
form.appendChild(sigInput);
|
||||||
|
|
||||||
|
// 设置表单目标 URL(不带参数)
|
||||||
|
form.action = `${ssoUrl.origin}${ssoUrl.pathname}`;
|
||||||
|
form.submit();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("登录错误:", error);
|
console.error("登录错误:", error);
|
||||||
@ -87,7 +107,12 @@ export function UserAuthForm({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn("grid gap-3", className)} {...props}>
|
<div className={cn("grid gap-3", className)} {...props}>
|
||||||
<form ref={formRef} method="get" style={{ display: "none" }} />
|
<form
|
||||||
|
ref={formRef}
|
||||||
|
method="get"
|
||||||
|
target="_self"
|
||||||
|
style={{ display: "none" }}
|
||||||
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={cn(buttonVariants({ variant: "outline" }))}
|
className={cn(buttonVariants({ variant: "outline" }))}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user