diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx
index b8c10dda69..14404f27d8 100644
--- a/packages/core/client/src/acl/ACLProvider.tsx
+++ b/packages/core/client/src/acl/ACLProvider.tsx
@@ -29,7 +29,6 @@ import { useDataSourceKey } from '../data-source/data-source/DataSourceProvider'
import { SchemaComponentOptions, useDesignable } from '../schema-component';
import { useApp } from '../application';
-import { NavigateToSigninWithRedirect } from '../user/CurrentUserProvider';
// 注意: 必须要对 useBlockRequestContext 进行引用,否则会导致 Data sources 页面报错,原因未知
useBlockRequestContext;
@@ -89,9 +88,6 @@ export const ACLRolesCheckProvider = (props) => {
if (result.loading) {
return render();
}
- if (result.error) {
- return ;
- }
return {props.children};
};
diff --git a/packages/core/client/src/route-switch/antd/admin-layout/index.tsx b/packages/core/client/src/route-switch/antd/admin-layout/index.tsx
index 316acd15d2..5142f86838 100644
--- a/packages/core/client/src/route-switch/antd/admin-layout/index.tsx
+++ b/packages/core/client/src/route-switch/antd/admin-layout/index.tsx
@@ -28,7 +28,6 @@ import {
CurrentAppInfoProvider,
findByUid,
findMenuItem,
- NavigateIfNotSignIn,
PinnedPluginList,
RemoteCollectionManagerProvider,
RemoteSchemaComponent,
@@ -543,17 +542,15 @@ export const AdminProvider = (props) => {
-
-
-
-
-
- {props.children}
-
-
-
-
-
+
+
+
+
+ {props.children}
+
+
+
+
diff --git a/packages/core/client/src/user/CurrentUserProvider.tsx b/packages/core/client/src/user/CurrentUserProvider.tsx
index 2c8a52c2e1..4b1dcab21b 100644
--- a/packages/core/client/src/user/CurrentUserProvider.tsx
+++ b/packages/core/client/src/user/CurrentUserProvider.tsx
@@ -8,10 +8,9 @@
*/
import React, { createContext, useContext, useMemo } from 'react';
-import { Navigate } from 'react-router-dom';
import { useACLRoleContext } from '../acl';
import { ReturnTypeOfUseRequest, useAPIClient, useRequest } from '../api-client';
-import { useAppSpin, useLocationNoUpdate } from '../application';
+import { useAppSpin } from '../application';
import { useCompile } from '../schema-component';
export const CurrentUserContext = createContext(null);
@@ -57,18 +56,3 @@ export const CurrentUserProvider = (props) => {
return {props.children};
};
-
-export const NavigateToSigninWithRedirect = () => {
- const { pathname, search } = useLocationNoUpdate();
- const redirect = `?redirect=${pathname}${search}`;
- return ;
-};
-
-export const NavigateIfNotSignIn = ({ children }) => {
- const result = useCurrentUserContext();
-
- if (result.loading === false && !result.data?.data?.id) {
- return ;
- }
- return <>{children}>;
-};
diff --git a/packages/plugins/@nocobase/plugin-auth/src/client/interceptors.ts b/packages/plugins/@nocobase/plugin-auth/src/client/interceptors.ts
index 5685fac6e1..cdde3bafa7 100644
--- a/packages/plugins/@nocobase/plugin-auth/src/client/interceptors.ts
+++ b/packages/plugins/@nocobase/plugin-auth/src/client/interceptors.ts
@@ -50,36 +50,34 @@ export function authCheckMiddleware({ app }: { app: Application }) {
};
const errHandler = (error) => {
const newToken = error?.response?.headers?.['x-new-token'];
+ const errors = error?.response?.data?.errors;
+ const firstError = Array.isArray(errors) ? errors[0] : null;
+
+ const state = app.router.state;
+ const { pathname, search } = state.location;
+ const basename = app.router.basename;
if (newToken) {
app.apiClient.auth.setToken(newToken);
}
- if (error.status === 401 && !error.config?.skipAuth) {
- const requestToken = error?.config?.headers?.Authorization?.replace(/^Bearer\s+/gi, '');
- const currentToken = app.apiClient.auth.getToken();
- // if (currentToken && currentToken !== requestToken) {
- // error.config.skipNotify = true;
- // return app.apiClient.request(error.config);
- // }
- app.apiClient.auth.setToken('');
- const errors = error?.response?.data?.errors;
- const firstError = Array.isArray(errors) ? errors[0] : null;
- if (!firstError) {
- throw error;
- }
- // if the code
- if (firstError?.code === AuthErrorCode.SKIP_TOKEN_RENEW) {
- throw error;
+ if (error.status === 401) {
+ app.apiClient.auth.setToken('');
+ if (pathname === app.getHref('signin') && firstError?.code !== AuthErrorCode.EMPTY_TOKEN && error.config) {
+ error.config.skipNotify = false;
}
if (firstError?.code === 'USER_HAS_NO_ROLES_ERR') {
+ // use app error to show error message
+ error.config.skipNotify = true;
app.error = firstError;
+ }
+ }
+
+ if (error.status === 401 && !error.config?.skipAuth) {
+ if (!firstError || firstError?.code === AuthErrorCode.SKIP_TOKEN_RENEW) {
throw error;
}
- const state = app.router.state;
- const { pathname, search } = state.location;
- const basename = app.router.basename;
if (pathname !== app.getHref('signin')) {
const redirectPath = removeBasename(pathname, basename);