mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 14:01:55 +08:00
refactor: 简化用户授权组件的登录逻辑,移除不必要的延迟和重定向处理
This commit is contained in:
parent
3f193650d2
commit
a5a9f2e779
@ -32,36 +32,21 @@ export function UserAuthorize({
|
|||||||
const sso = url.searchParams.get("sso");
|
const sso = url.searchParams.get("sso");
|
||||||
const sig = url.searchParams.get("sig");
|
const sig = url.searchParams.get("sig");
|
||||||
|
|
||||||
console.log("准备登录,参数:", {
|
|
||||||
sso: sso?.substring(0, 20) + "...",
|
|
||||||
sig: sig?.substring(0, 20) + "...",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!sso || !sig) {
|
if (!sso || !sig) {
|
||||||
throw new Error("缺少必要的认证参数");
|
throw new Error("缺少必要的认证参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 直接调用signIn,它会处理SSO回调中的return_sso_url
|
||||||
await signIn({ sso, sig });
|
await signIn({ sso, sig });
|
||||||
// 更新 session
|
// 更新session状态
|
||||||
await update();
|
await update();
|
||||||
// 添加更长的延迟确保session完全更新
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
||||||
// 检查URL中是否存在重定向参数
|
|
||||||
const redirectTo = url.searchParams.get("redirect_to");
|
|
||||||
if (redirectTo) {
|
|
||||||
// 如果存在重定向参数,则跳转到指定的URL
|
|
||||||
window.location.href = redirectTo;
|
|
||||||
} else {
|
|
||||||
// 如果不存在重定向参数,则刷新当前页面状态
|
|
||||||
router.refresh();
|
|
||||||
}
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("登录过程出错:", error);
|
console.error("登录过程出错:", error);
|
||||||
setError(error);
|
setError(error);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
}, [isLoading, update, router]);
|
}, [isLoading, update]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(signInCallback, 5);
|
const timer = setTimeout(signInCallback, 5);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user