feat: authorize routes added
This commit is contained in:
@@ -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
14
src/lib/identityClient.ts
Normal 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',
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user