| | |
| | |
| | |
| |
|
| | const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ""; |
| |
|
| | |
| | |
| | |
| | |
| | export async function getCurrentUser() { |
| | const token = localStorage.getItem("auth_token"); |
| | if (!token) { |
| | throw new Error("No token found"); |
| | } |
| |
|
| | const response = await fetch(`${API_BASE_URL}/api/auth/me`, { |
| | method: "GET", |
| | headers: { |
| | Authorization: `Bearer ${token}`, |
| | }, |
| | }); |
| |
|
| | if (!response.ok) { |
| | if (response.status === 401) { |
| | localStorage.removeItem("auth_token"); |
| | } |
| | const errorData = await response.json().catch(() => ({})); |
| | throw new Error(errorData.detail || "Failed to get user"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function firebaseLogin(idToken) { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/firebase/login`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | }, |
| | body: JSON.stringify({ id_token: idToken }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({})); |
| | throw new Error(errorData.detail || "Firebase login failed"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function requestOTP(email) { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/otp/request`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | }, |
| | body: JSON.stringify({ email }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({})); |
| | throw new Error(errorData.detail || "Failed to send OTP"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export async function verifyOTP(email, otp) { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/otp/verify`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | }, |
| | body: JSON.stringify({ email, otp }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({})); |
| | throw new Error(errorData.detail || "OTP verification failed"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export async function logout() { |
| | |
| | |
| | return Promise.resolve(); |
| | } |
| |
|