修复登录成功后页面卡在处理中的问题

This commit is contained in:
Your Name 2026-02-09 02:23:41 +08:00
parent 42173615a5
commit 419712f1bf

View File

@ -41,6 +41,8 @@ export default function Page() {
// 系统通知状态
const [notification, setNotification] = useState<{ enabled: boolean; title: string; content: string } | null>(null);
const [showNotification, setShowNotification] = useState(false);
const loginRedirectTimerRef = useRef<number | null>(null);
const loginRedirectFallbackTimerRef = useRef<number | null>(null);
const iframeRef = useRef<HTMLIFrameElement>(null);
@ -265,29 +267,58 @@ export default function Page() {
// 处理登录状态变化
useEffect(() => {
if (loginRedirectTimerRef.current) {
window.clearTimeout(loginRedirectTimerRef.current);
loginRedirectTimerRef.current = null;
}
if (loginRedirectFallbackTimerRef.current) {
window.clearTimeout(loginRedirectFallbackTimerRef.current);
loginRedirectFallbackTimerRef.current = null;
}
if (state.status === "failed") {
setIsSuccessful(false);
setIsHandlingToken(false);
toast({
type: "error",
description: "邮箱或密码不正确",
});
} else if (state.status === "invalid_data") {
setIsSuccessful(false);
setIsHandlingToken(false);
toast({
type: "error",
description: "提交的信息校验失败",
});
} else if (state.status === "success") {
toast({ type: "success", description: "登录成功,正在进入首页" });
setIsSuccessful(true);
window.location.href = "/";
loginRedirectTimerRef.current = window.setTimeout(() => {
window.location.replace("/");
}, 120);
loginRedirectFallbackTimerRef.current = window.setTimeout(() => {
window.location.assign("/");
}, 1600);
}
}, [state.status]);
const handleSubmit = (formData: FormData) => {
setIsSuccessful(false);
setEmail(formData.get("email") as string);
formAction(formData);
};
useEffect(() => {
return () => {
if (loginRedirectTimerRef.current) {
window.clearTimeout(loginRedirectTimerRef.current);
}
if (loginRedirectFallbackTimerRef.current) {
window.clearTimeout(loginRedirectFallbackTimerRef.current);
}
};
}, []);
// 根据组织名称启动钉钉登录(在 iframe 中打开)
const startDingTalkLoginForOrg = (orgName: string) => {
// 清除 URL 中的 token 参数,避免干扰