feat: refresh token added
This commit is contained in:
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user