import { getAccessToken, removeToken, getUser, isAuthenticated, getRawToken } from "../tokenUtility"; const API_BASE_URL = process.env.REACT_APP_API_URL || ""; export { isAuthenticated }; export function getCurrentUser() { return getUser(); } export function getToken() { return getRawToken(); } export function logout() { removeToken(); } export async function changePassword(currentPassword, newPassword, confirmPassword) { const response = await fetch(`${API_BASE_URL}/api/Authentication/ChangePassword`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": getAccessToken(), }, body: JSON.stringify({ Currentpassword: currentPassword, Newpassword: newPassword, Confirmpassword: confirmPassword, }), }); if (!response.ok) { throw new Error("Failed to change password"); } return await response.json(); } export async function forgotPassword(email) { const response = await fetch(`${API_BASE_URL}/api/Authentication/ForgetPassword?Email=${encodeURIComponent(email)}`, { method: "POST", headers: { "Content-Type": "application/json", }, }); if (!response.ok) { throw new Error("Failed to send password reset email"); } return await response.json(); } export async function verifyResetCode(code) { const response = await fetch(`${API_BASE_URL}/api/Authentication/VerificationCode?code=${encodeURIComponent(code)}`, { method: "POST", headers: { "Content-Type": "application/json", }, }); if (!response.ok) { throw new Error("Invalid verification code"); } return await response.json(); } export async function resetPassword(email, code, password) { const response = await fetch(`${API_BASE_URL}/api/Authentication/ResetPassword`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ Email: email, Code: code, Password: password, }), }); if (!response.ok) { throw new Error("Failed to reset password"); } return await response.json(); }