fix: stabilize admin social redirect
This commit is contained in:
@@ -683,6 +683,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForAdminSession(maxAttempts = 8) {
|
||||
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
||||
try {
|
||||
const response = await fetch('/yuyx/api/admin-auth/social/session', {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store'
|
||||
});
|
||||
if (response.ok) {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
// retry below
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 180 + attempt * 120));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function handleSocialCallback() {
|
||||
const params = new URLSearchParams(window.location.search || '');
|
||||
const provider = String(params.get('provider') || params.get('type') || '').trim();
|
||||
@@ -703,17 +722,24 @@
|
||||
return;
|
||||
}
|
||||
showSuccess('登录成功,正在跳转...');
|
||||
window.setTimeout(() => {
|
||||
window.location.replace(data.redirect || '/yuyx/admin');
|
||||
}, 500);
|
||||
await waitForAdminSession();
|
||||
window.location.replace(data.redirect || '/yuyx/admin');
|
||||
} catch (error) {
|
||||
showError('快捷登录失败');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const params = new URLSearchParams(window.location.search || '');
|
||||
const hasSocialCallback = Boolean(
|
||||
String(params.get('code') || '').trim()
|
||||
&& String(params.get('provider') || params.get('type') || '').trim()
|
||||
);
|
||||
if (hasSocialCallback) {
|
||||
handleSocialCallback();
|
||||
return;
|
||||
}
|
||||
loadSocialConfig();
|
||||
handleSocialCallback();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user