feat: refresh token added

This commit is contained in:
مهرزاد قدرتی
2025-08-16 14:38:45 +03:30
parent ba73dbf191
commit 0548118208
5 changed files with 122 additions and 8 deletions

View File

@@ -1,9 +1,6 @@
import { getAccessToken } from '@/features/authorization/api/identityAPI';
import axios from 'axios';
// Function to get the token from local storage or state management
export const ACCESS_TOKEN_KEY: 'access_token' = 'access_token' as const;
export const getAccessToken = () => sessionStorage.getItem(ACCESS_TOKEN_KEY);
const apiClient = axios.create({
// Define the base URL for all API requests
baseURL: import.meta.env.VITE_API_URL,
@@ -21,8 +18,8 @@ const apiClient = axios.create({
// --- Request Interceptor ---
// This runs BEFORE each request is sent
apiClient.interceptors.request.use(
(config) => {
const token = getAccessToken();
async (config) => {
const token = await getAccessToken();
if (token) {
// Add the authorization token to the headers
config.headers.Authorization = `Bearer ${token}`;