chore: build
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getToken, getAdminToken } from "../auth/tokenStorage";
|
import { getToken, getAdminToken } from "../auth/tokenStorage";
|
||||||
|
|
||||||
export const API_BASE_URL = process.env.EXPO_PUBLIC_API_URL ?? "https://mln-uber.club";
|
export const API_BASE_URL =
|
||||||
|
process.env.EXPO_PUBLIC_API_URL ?? "https://mln-uber.club";
|
||||||
|
|
||||||
const apiClient = axios.create({
|
const apiClient = axios.create({
|
||||||
baseURL: API_BASE_URL,
|
baseURL: API_BASE_URL,
|
||||||
@@ -11,7 +12,7 @@ const apiClient = axios.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Request interceptor: attach JWT token
|
// attach JWT token
|
||||||
apiClient.interceptors.request.use(async (config) => {
|
apiClient.interceptors.request.use(async (config) => {
|
||||||
const isAdminRoute =
|
const isAdminRoute =
|
||||||
config.url?.includes("/api/v2/") ||
|
config.url?.includes("/api/v2/") ||
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
// ============================================
|
// ============================================
|
||||||
// api/api.ts - VERSION CORRIGÉE
|
// api/api.ts - VERSION CORRIGÉE
|
||||||
// ============================================
|
// ============================================
|
||||||
// ✅ AuthResponse inclut access_token
|
|
||||||
// ✅ loginUser et registerUser retournent AuthResponse
|
|
||||||
// ✅ sessionStorage (pas localStorage)
|
|
||||||
const API_URL = "/api/v1";
|
const API_URL = "/api/v1";
|
||||||
const BACKEND_URL = "";
|
const BACKEND_URL = "";
|
||||||
export function getMediaUrl(url: string): string {
|
export function getMediaUrl(url: string): string {
|
||||||
@@ -1949,29 +1947,50 @@ export const verify2FA = async (
|
|||||||
user: data.user,
|
user: data.user,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { success: false, message: error instanceof Error ? error.message : "Erreur" };
|
return {
|
||||||
|
success: false,
|
||||||
|
message: error instanceof Error ? error.message : "Erreur",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const get2FAStatus = async (): Promise<{ two_fa_enabled: boolean; telegram_linked: boolean; admin_2fa_enabled: boolean }> => {
|
export const get2FAStatus = async (): Promise<{
|
||||||
|
two_fa_enabled: boolean;
|
||||||
|
telegram_linked: boolean;
|
||||||
|
admin_2fa_enabled: boolean;
|
||||||
|
}> => {
|
||||||
const token = sessionStorage.getItem("token");
|
const token = sessionStorage.getItem("token");
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/two-fa/status`, {
|
const response = await fetch(`${API_URL}/two-fa/status`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
});
|
});
|
||||||
if (!response.ok) return { two_fa_enabled: false, telegram_linked: false, admin_2fa_enabled: false };
|
if (!response.ok)
|
||||||
|
return {
|
||||||
|
two_fa_enabled: false,
|
||||||
|
telegram_linked: false,
|
||||||
|
admin_2fa_enabled: false,
|
||||||
|
};
|
||||||
return await safeJson(response);
|
return await safeJson(response);
|
||||||
} catch {
|
} catch {
|
||||||
return { two_fa_enabled: false, telegram_linked: false, admin_2fa_enabled: false };
|
return {
|
||||||
|
two_fa_enabled: false,
|
||||||
|
telegram_linked: false,
|
||||||
|
admin_2fa_enabled: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const toggle2FA = async (enabled: boolean): Promise<{ success: boolean; error?: string }> => {
|
export const toggle2FA = async (
|
||||||
|
enabled: boolean,
|
||||||
|
): Promise<{ success: boolean; error?: string }> => {
|
||||||
const token = sessionStorage.getItem("token");
|
const token = sessionStorage.getItem("token");
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/two-fa/toggle`, {
|
const response = await fetch(`${API_URL}/two-fa/toggle`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
body: JSON.stringify({ enabled }),
|
body: JSON.stringify({ enabled }),
|
||||||
});
|
});
|
||||||
const data = await safeJson(response);
|
const data = await safeJson(response);
|
||||||
|
|||||||
@@ -157,9 +157,6 @@ export const getProductById = async (id: number) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// CART
|
|
||||||
|
|
||||||
export const getCart = async (username: string) => {
|
export const getCart = async (username: string) => {
|
||||||
const jwtUsername = await getJwtUsername();
|
const jwtUsername = await getJwtUsername();
|
||||||
if (!jwtUsername || jwtUsername !== username) {
|
if (!jwtUsername || jwtUsername !== username) {
|
||||||
|
|||||||
Reference in New Issue
Block a user