优化
This commit is contained in:
+1
-1
@@ -95,7 +95,7 @@ transport.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
const request = error.config as RetryableRequest | undefined
|
||||
const publicAuthPaths = ['/auth/login', '/auth/register', '/auth/refresh']
|
||||
const publicAuthPaths = ['/auth/login', '/auth/register', '/auth/refresh', '/auth/impersonations/exchange']
|
||||
const isPublicAuthRequest = publicAuthPaths.some((path) => request?.url?.endsWith(path))
|
||||
if (error.response?.status !== 401 || !request || request._retriedAfterRefresh || isPublicAuthRequest) {
|
||||
throw mapError(error)
|
||||
|
||||
@@ -92,6 +92,13 @@ test('uses real auth endpoints and single-flight refresh handling', () => {
|
||||
assert.doesNotMatch(authStoreSource, /mock-client:/)
|
||||
})
|
||||
|
||||
test('handles impersonation exchange as public authentication and exposes failures', () => {
|
||||
assert.match(httpSource, /publicAuthPaths = \[[^\]]*'\/auth\/impersonations\/exchange'/)
|
||||
assert.match(authStoreSource, /\/login\?impersonation=failed/)
|
||||
assert.match(loginSource, /route\.query\.impersonation === 'failed'/)
|
||||
assert.match(loginSource, /代登录失败或授权已失效,请返回管理后台重新发起/)
|
||||
})
|
||||
|
||||
test('treats only body code 200 as success', () => {
|
||||
assert.match(httpSource, /if \(envelope\.code !== '200'\)/)
|
||||
assert.doesNotMatch(httpSource, /if \(envelope\.code !== '0'\)/)
|
||||
|
||||
@@ -17,6 +17,7 @@ const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const impersonationFailed = route.query.impersonation === 'failed'
|
||||
const form = reactive<LoginForm>({
|
||||
account: typeof route.query.account === 'string'
|
||||
? route.query.account
|
||||
@@ -77,6 +78,13 @@ function showResetHint() {
|
||||
<h2 id="login-title">登录客户工作台</h2>
|
||||
<p>使用企业账号登录,继续管理您的跨境物流业务。</p>
|
||||
</div>
|
||||
<el-alert
|
||||
v-if="impersonationFailed"
|
||||
title="代登录失败或授权已失效,请返回管理后台重新发起"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<div class="auth-account-note">企业注册成功后即可登录;提交订单前需完成企业资料审核。</div>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-position="top" size="large" @submit.prevent="submit">
|
||||
<el-form-item label="用户名" prop="account">
|
||||
|
||||
Reference in New Issue
Block a user