refactor: replace localStorage with appStorage for token management in apiClient

This commit is contained in:
Firman Ramdhani
2026-07-27 12:29:44 +07:00
parent 94fc29722c
commit 0f9b44e70f
+2 -2
View File
@@ -32,7 +32,7 @@ export const apiClient = createHttpClient(
const language = await appStorage.getItem<string>(AppStorageKey.LANGUAGE); const language = await appStorage.getItem<string>(AppStorageKey.LANGUAGE);
config.headers['ex-language'] = language ?? ENV.DEFAULT_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}`; if (token) config.headers.Authorization = `Bearer ${token}`;
return config; return config;
@@ -42,7 +42,7 @@ export const apiClient = createHttpClient(
onResponseError: async (error) => { onResponseError: async (error) => {
if (error.response?.status === 401) { if (error.response?.status === 401) {
// Clear stale token and redirect to login // Clear stale token and redirect to login
localStorage.removeItem('access_token'); await appStorage.removeItem(AppStorageKey.ACCESS_TOKEN);
window.location.href = '/auth/login'; window.location.href = '/auth/login';
} }
throw error; throw error;