fix: 登录页401时,不再触发window.location.href='/'
This commit is contained in:
1 parent
016f992346
commit
2e9a70933d
2 files changed
+12
-4
No files matched your search
@@ -22,6 +22,10 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Res
|
||||
: (input instanceof URL ? input.toString() : input.url);
|
||||
const isApi = url.includes('/api/');
|
||||
const isRefreshApi = url.includes('/api/user/casdoor/refresh');
|
||||
const isLoginApi =
|
||||
url.includes('/api/user/login') ||
|
||||
url.includes('/api/user/casdoor/password-login') ||
|
||||
url.includes('/api/user/casdoor/login');
|
||||
if (res.status === 401 && isApi && !isRefreshApi) {
|
||||
// First unauthorized response: try silent refresh once.
|
||||
const refreshed = await refreshAccessToken();
|
||||
@@ -33,7 +37,7 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Res
|
||||
res = await runFetch(reqInit);
|
||||
}
|
||||
}
|
||||
if (res.status === 401 && isApi) {
|
||||
if (res.status === 401 && isApi && !isLoginApi) {
|
||||
// Still unauthorized after retry (or no refresh token): force global logout UX.
|
||||
window.dispatchEvent(new CustomEvent('hxops:unauthorized', { detail: { url, status: res.status } }));
|
||||
}
|
||||
|
||||
@@ -409,7 +409,10 @@ const persistLoginUser = (user: any) => {
|
||||
|
||||
const DEFAULT_POST_LOGIN_AGENT_ID = 16;
|
||||
|
||||
const handleLogin = async () => {
|
||||
const handleLogin = async (event?: Event) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
|
||||
if (!loginUsername.value.trim()) {
|
||||
showMessageDialog('warning', t('login.usernameRequired'));
|
||||
return;
|
||||
@@ -1298,11 +1301,12 @@ onMounted(async () => {
|
||||
<label for="rememberMe" class="text-sm text-slate-600 cursor-pointer select-none">{{ $t('login.rememberMe') }}</label>
|
||||
</div>
|
||||
|
||||
<button @click="handleLogin" class="btn-primary w-full py-3 text-base shadow-brand-500/40 hover:shadow-brand-500/50 transform hover:-translate-y-0.5 transition-all mt-4">
|
||||
<button type="button" @click="handleLogin" class="btn-primary w-full py-3 text-base shadow-brand-500/40 hover:shadow-brand-500/50 transform hover:-translate-y-0.5 transition-all mt-4">
|
||||
{{ $t('login.submit') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
v-if="config.auth?.wecom?.enabled && (!config.auth?.wecom?.loginViaCasdoor || config.auth?.casdoor?.enabled)"
|
||||
@click="handleWecomLogin"
|
||||
:disabled="isWecomLoggingIn"
|
||||
@@ -1312,7 +1316,7 @@ onMounted(async () => {
|
||||
</button>
|
||||
|
||||
<div class="flex justify-between items-center pt-4 mt-2 border-t border-slate-100/50">
|
||||
<button @click="showForgotPasswordModal = true" class="text-sm text-slate-500 hover:text-brand-600 transition-colors">
|
||||
<button type="button" @click="showForgotPasswordModal = true" class="text-sm text-slate-500 hover:text-brand-600 transition-colors">
|
||||
{{ $t('login.forgotPassword') }}
|
||||
</button>
|
||||
<!-- 点击注册 -->
|
||||
|
||||
Reference in new issue
Block a user