chore: fix url api
This commit is contained in:
@@ -9,8 +9,8 @@ import type {
|
||||
Alert,
|
||||
} from "./types";
|
||||
|
||||
const V2 = "http://172.20.167.237:8080/api/v2";
|
||||
const CABINE_URL = "http://172.20.167.237:8080/api/v1/cabine";
|
||||
const V2 = "https://uber-stup.club/api/v2";
|
||||
const CABINE_URL = "https://uber-stup.club/api/v1/cabine";
|
||||
|
||||
// ============================================
|
||||
// AUTH
|
||||
@@ -378,7 +378,7 @@ export const createClientByAdmin = async (data: {
|
||||
telephone: string;
|
||||
}) => {
|
||||
const { data: res } = await apiClient.post(
|
||||
`http://172.20.167.237:8080/api/v1/auth/register`,
|
||||
`https://uber-stup.club/api/v1/auth/register`,
|
||||
data,
|
||||
);
|
||||
return {
|
||||
|
||||
@@ -6,8 +6,8 @@ import type {
|
||||
Alert,
|
||||
} from "./types";
|
||||
|
||||
const API = "http://172.20.167.237:8080/api/v1/cabine";
|
||||
const V2 = "http://172.20.167.237:8080/api/v2";
|
||||
const API = "https://uber-stup.club/api/v1/cabine";
|
||||
const V2 = "https://uber-stup.club/api/v2";
|
||||
|
||||
// ============================================
|
||||
// ITEMS
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
Alert,
|
||||
} from "./types";
|
||||
|
||||
const API = "http://172.20.167.237:8080/api/v1/livreur";
|
||||
const API = "https://uber-stup.club/api/v1/livreur";
|
||||
|
||||
// ============================================
|
||||
// STATUT
|
||||
|
||||
@@ -1,43 +1,42 @@
|
||||
import axios from 'axios';
|
||||
import { getToken, getAdminToken } from '../auth/tokenStorage';
|
||||
import axios from "axios";
|
||||
import { getToken, getAdminToken } from "../auth/tokenStorage";
|
||||
|
||||
// Change this to your server IP/domain
|
||||
export const API_BASE_URL = 'http://localhost:8080';
|
||||
export const API_BASE_URL = "https://uber-stup.club";
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
// Request interceptor: attach JWT token
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
// Determine which token to use based on URL
|
||||
const isAdminRoute = config.url?.includes('/api/v2/') ||
|
||||
config.url?.includes('/api/v1/cabine/') ||
|
||||
config.url?.includes('/api/v1/livreur/');
|
||||
// Determine which token to use based on URL
|
||||
const isAdminRoute =
|
||||
config.url?.includes("/api/v2/") ||
|
||||
config.url?.includes("/api/v1/cabine/") ||
|
||||
config.url?.includes("/api/v1/livreur/");
|
||||
|
||||
const token = isAdminRoute
|
||||
? await getAdminToken()
|
||||
: await getToken();
|
||||
const token = isAdminRoute ? await getAdminToken() : await getToken();
|
||||
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
// Response interceptor: handle common errors
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
console.log('Session expirée');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
console.log("Session expirée");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
|
||||
export default apiClient;
|
||||
|
||||
Reference in New Issue
Block a user