feat: authorize routes added

This commit is contained in:
2025-08-16 00:01:03 +03:30
parent e9b43b9e53
commit 2ad191064e
7 changed files with 41 additions and 7 deletions

View File

@@ -1,7 +1,8 @@
import axios from 'axios';
// Function to get the token from local storage or state management
const getToken = () => sessionStorage.getItem('authToken');
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
@@ -21,7 +22,7 @@ const apiClient = axios.create({
// This runs BEFORE each request is sent
apiClient.interceptors.request.use(
(config) => {
const token = getToken();
const token = getAccessToken();
if (token) {
// Add the authorization token to the headers
config.headers.Authorization = `Bearer ${token}`;

14
src/lib/identityClient.ts Normal file
View File

@@ -0,0 +1,14 @@
import axios from 'axios';
const identityClient = axios.create({
// Define the base URL for all API requests
baseURL: import.meta.env.VITE_IDENTITY_URL,
// Set a timeout for requests (e.g., 10 seconds)
timeout: 10000,
// Set default headers
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});