mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: add optional chaining for safe access to response headers in auth middleware
This commit is contained in:
parent
1834cd6f05
commit
5393e3ddd8
@ -42,20 +42,20 @@ const debouncedRedirect = debounce(
|
||||
export function authCheckMiddleware({ app }: { app: Application }) {
|
||||
const axios = app.apiClient.axios;
|
||||
const resHandler = (res: AxiosResponse) => {
|
||||
const newToken = res.headers['x-new-token'];
|
||||
const newToken = res?.headers?.['x-new-token'];
|
||||
if (newToken) {
|
||||
app.apiClient.auth.setToken(newToken);
|
||||
}
|
||||
return res;
|
||||
};
|
||||
const errHandler = (error) => {
|
||||
const newToken = error.response.headers['x-new-token'];
|
||||
const newToken = error?.response?.headers?.['x-new-token'];
|
||||
|
||||
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 requestToken = error?.config?.headers?.Authorization?.replace(/^Bearer\s+/gi, '');
|
||||
const currentToken = app.apiClient.auth.getToken();
|
||||
if (currentToken && currentToken !== requestToken) {
|
||||
error.config.skipNotify = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user