fix(auth): 401拦截器排除auth端点 + login默认跳转/app/dashboard (#1228)
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m7s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m8s
CI/CD Pipeline / Frontend Unit Tests (push) Failing after 2m22s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m1s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m15s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m2s
CI/CD Pipeline / Integration Tests (push) Successful in 2m6s
CI/CD Pipeline / Unit Tests (push) Successful in 10m29s
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m41s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 40s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 18s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 32s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 53s
CI/CD Pipeline / Canary Release to Production (push) Failing after 1056h27m41s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 1056h30m52s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1056h30m51s
CI/CD Pipeline / Build Production Web Image (push) Failing after 1056h30m52s
CI/CD Pipeline / Deploy Production (push) Failing after 1056h30m51s
CI/CD Pipeline / PR Build Web Image (push) Failing after 1056h41m20s
CI/CD Pipeline / Build Production API Image (push) Failing after 1056h30m52s
CI/CD Pipeline / PR Build API Image (push) Failing after 1056h41m22s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 1056h41m24s
CI/CD Pipeline / CI Gate (push) Failing after 1057h4m6s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 1057h14m35s
CI/CD Pipeline / Frontend Lint (push) Failing after 1057h14m37s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m7s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m8s
CI/CD Pipeline / Frontend Unit Tests (push) Failing after 2m22s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m1s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m15s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m2s
CI/CD Pipeline / Integration Tests (push) Successful in 2m6s
CI/CD Pipeline / Unit Tests (push) Successful in 10m29s
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m41s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 40s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 18s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 32s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 53s
CI/CD Pipeline / Canary Release to Production (push) Failing after 1056h27m41s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 1056h30m52s
CI/CD Pipeline / Production Browser E2E (push) Failing after 1056h30m51s
CI/CD Pipeline / Build Production Web Image (push) Failing after 1056h30m52s
CI/CD Pipeline / Deploy Production (push) Failing after 1056h30m51s
CI/CD Pipeline / PR Build Web Image (push) Failing after 1056h41m20s
CI/CD Pipeline / Build Production API Image (push) Failing after 1056h30m52s
CI/CD Pipeline / PR Build API Image (push) Failing after 1056h41m22s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 1056h41m24s
CI/CD Pipeline / CI Gate (push) Failing after 1057h4m6s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 1057h14m35s
CI/CD Pipeline / Frontend Lint (push) Failing after 1057h14m37s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
This commit was merged in pull request #1228.
This commit is contained in:
@@ -57,7 +57,21 @@ apiClient.interceptors.response.use(
|
||||
}
|
||||
|
||||
// 401 → 尝试刷新 Token
|
||||
if (error.response?.status === 401 && originalRequest && !originalRequest._retry) {
|
||||
// 排除 auth 端点:登录/注册/找回密码的 401 是正常业务响应(如密码错误),
|
||||
// 不应触发 token 刷新或登出跳转,走后面的错误提示逻辑即可
|
||||
const requestUrl = originalRequest?.url || ""
|
||||
const isAuthEndpoint =
|
||||
requestUrl.includes("/auth/login") ||
|
||||
requestUrl.includes("/auth/register") ||
|
||||
requestUrl.includes("/auth/forgot-password") ||
|
||||
requestUrl.includes("/auth/reset-password")
|
||||
|
||||
if (
|
||||
error.response?.status === 401 &&
|
||||
originalRequest &&
|
||||
!originalRequest._retry &&
|
||||
!isAuthEndpoint
|
||||
) {
|
||||
const refreshToken = useAuthStore.getState().refreshToken
|
||||
|
||||
// 无 refresh_token → 直接登出
|
||||
|
||||
@@ -31,8 +31,8 @@ export const useLogin = () => {
|
||||
const user = await authApi.getCurrentUser()
|
||||
setAuth(user, data.access_token, refreshToken)
|
||||
|
||||
// 跳转到登录前页面或首页
|
||||
const redirect = localStorage.getItem("login_redirect") || "/"
|
||||
// 跳转到登录前页面或仪表盘(与 Login.tsx onFinish 保持一致)
|
||||
const redirect = localStorage.getItem("login_redirect") || "/app/dashboard"
|
||||
localStorage.removeItem("login_redirect")
|
||||
navigate(redirect, { replace: true })
|
||||
return data
|
||||
|
||||
@@ -61,7 +61,9 @@ set -e
|
||||
echo "$VITEST_OUTPUT"
|
||||
|
||||
# 如果没有找到测试文件,视为通过(改动的文件没有对应测试)
|
||||
if echo "$VITEST_OUTPUT" | grep -q "No test files found"; then
|
||||
# 先用 sed 去掉 ANSI 转义码,避免干扰 grep 匹配
|
||||
CLEAN_OUTPUT=$(echo "$VITEST_OUTPUT" | sed 's/\x1b\[[0-9;]*m//g')
|
||||
if echo "$CLEAN_OUTPUT" | grep -q "No test files found"; then
|
||||
echo ""
|
||||
echo "⚠️ 未找到相关测试文件,跳过(非失败)"
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user