refactor(auth): standardize authorization token handling
- Replace 'token' with 'Authorization' in localStorage keys for consistency - Update auth guard, request interceptor and login hooks to use new key - Add updateAuthorization method to auth hook for better state management
This commit is contained in:
@@ -47,12 +47,12 @@ export type ResultCode =
|
||||
|
||||
// 获取授权token
|
||||
const getAuthorization = (): string => {
|
||||
return localStorage.getItem('token') || '';
|
||||
return localStorage.getItem(Authorization) || '';
|
||||
};
|
||||
|
||||
// 重定向到登录页
|
||||
const redirectToLogin = (): void => {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem(Authorization);
|
||||
window.location.href = '/login';
|
||||
};
|
||||
|
||||
@@ -94,9 +94,9 @@ request.interceptors.request.use(
|
||||
}
|
||||
|
||||
// 添加授权头
|
||||
const token = getAuthorization();
|
||||
if (token && !config.headers?.skipToken) {
|
||||
config.headers[Authorization] = token;
|
||||
const authorization = getAuthorization();
|
||||
if (authorization && !config.headers?.skipToken) {
|
||||
config.headers.Authorization = authorization;
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
Reference in New Issue
Block a user