refactor: replace localStorage with appStorage for token management in apiClient
This commit is contained in:
@@ -32,7 +32,7 @@ export const apiClient = createHttpClient(
|
||||
const language = await appStorage.getItem<string>(AppStorageKey.LANGUAGE);
|
||||
config.headers['ex-language'] = language ?? ENV.DEFAULT_LANGUAGE;
|
||||
|
||||
const token = localStorage.getItem('access_token');
|
||||
const token = await appStorage.getItem<string>(AppStorageKey.ACCESS_TOKEN);
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`;
|
||||
|
||||
return config;
|
||||
@@ -42,7 +42,7 @@ export const apiClient = createHttpClient(
|
||||
onResponseError: async (error) => {
|
||||
if (error.response?.status === 401) {
|
||||
// Clear stale token and redirect to login
|
||||
localStorage.removeItem('access_token');
|
||||
await appStorage.removeItem(AppStorageKey.ACCESS_TOKEN);
|
||||
window.location.href = '/auth/login';
|
||||
}
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user