mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
refactor: Simplify SSO authentication redirect to use direct window location
This commit is contained in:
parent
849265a26f
commit
bcec776a00
@ -20,7 +20,6 @@ export function UserAuthForm({
|
||||
const router = useRouter();
|
||||
const { toast } = useToast();
|
||||
const searchParams = useSearchParams();
|
||||
const formRef = React.useRef<HTMLFormElement>(null);
|
||||
|
||||
async function signIn() {
|
||||
try {
|
||||
@ -66,31 +65,8 @@ export function UserAuthForm({
|
||||
const data = await response.json();
|
||||
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 && sso && sig) {
|
||||
const form = formRef.current;
|
||||
// 创建隐藏的输入字段
|
||||
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();
|
||||
}
|
||||
// 直接使用 window.location.href 跳转
|
||||
window.location.href = data.sso_url;
|
||||
} catch (error) {
|
||||
console.error("登录错误:", error);
|
||||
toast({
|
||||
@ -107,12 +83,6 @@ export function UserAuthForm({
|
||||
|
||||
return (
|
||||
<div className={cn("grid gap-3", className)} {...props}>
|
||||
<form
|
||||
ref={formRef}
|
||||
method="get"
|
||||
target="_self"
|
||||
style={{ display: "none" }}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(buttonVariants({ variant: "outline" }))}
|
||||
|
Loading…
x
Reference in New Issue
Block a user