From 26045484f68677c89de627ef05bc2de230e1b605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Wed, 22 Oct 2025 01:29:40 -0500 Subject: [PATCH] Added missing password API services. --- src/api/auth/api.js | 75 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/src/api/auth/api.js b/src/api/auth/api.js index 6726f9f..dff1c2b 100644 --- a/src/api/auth/api.js +++ b/src/api/auth/api.js @@ -23,7 +23,6 @@ const MOCK_CREDENTIALS = { const login = async ({ username, password }) => { await simulateDelay(); - // Simulate API call if ( username === MOCK_CREDENTIALS.username && password === MOCK_CREDENTIALS.password @@ -55,7 +54,6 @@ const login = async ({ username, password }) => { const logout = async (token) => { await simulateDelay(300); - // Simulate successful logout return { data: { message: "Logged out successfully" }, status: 200, @@ -70,7 +68,6 @@ const logout = async (token) => { const register = async ({ email, password }) => { await simulateDelay(); - // Simulate registration const token = "mock_jwt_token_" + Date.now(); return { @@ -126,10 +123,82 @@ const refresh = async (refreshToken) => { // return POST(AUTH_ENDPOINTS.REFRESH, { refreshToken }); }; +// Request Password Reset - Send reset email +const requestPasswordReset = async ({ email }) => { + await simulateDelay(); + + return { + data: { + message: "Password reset email sent. Please check your inbox.", + email, + }, + status: 200, + ok: true, + }; + + // Real API call (commented out for now) + // return POST(AUTH_ENDPOINTS.REQUEST_PASSWORD_RESET, { email }); +}; + +// Reset Password - Set new password with token +const resetPassword = async ({ token, password }) => { + await simulateDelay(); + + if (token && password.length >= 6) { + return { + data: { + message: + "Password has been reset successfully. You can now log in with your new password.", + }, + status: 200, + ok: true, + }; + } + + return { + data: { message: "Invalid or expired reset token" }, + status: 400, + ok: false, + }; + + // Real API call (commented out for now) + // return POST(AUTH_ENDPOINTS.RESET_PASSWORD, { token, password }); +}; + +// Change Password - Change password while logged in +const changePassword = async ({ currentPassword, newPassword, token }) => { + await simulateDelay(); + + if (currentPassword === "demo123" && newPassword.length >= 6) { + return { + data: { + message: "Password changed successfully.", + }, + status: 200, + ok: true, + }; + } + + return { + data: { message: "Current password is incorrect" }, + status: 400, + ok: false, + }; + + // Real API call (commented out for now) + // return POST(AUTH_ENDPOINTS.CHANGE_PASSWORD, + // { currentPassword, newPassword }, + // { headers: getAuthHeaders(token) } + // ); +}; + export const AUTH = { login, logout, register, me, refresh, + requestPasswordReset, + resetPassword, + changePassword, };