From b7a08b687d7c62c2dd1a7bb3048e4593f2c80ada Mon Sep 17 00:00:00 2001 From: AI Bot Date: Thu, 17 Sep 2026 08:55:31 +0530 Subject: [PATCH] fix: Add missing auth API methods --- src/lib/api.ts | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/lib/api.ts b/src/lib/api.ts index cf669d9..01f2e27 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -117,6 +117,71 @@ export const api = { if (!res.ok) throw new Error(data.error); return data; }, + + addUser: async (userData) => { + const res = await fetch(`${API_URL}/users`, { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(userData) + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, + + deleteUser: async (id) => { + const res = await fetch(`${API_URL}/users/${id}`, { + method: 'DELETE', + headers: getHeaders() + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, + + triggerPasswordReset: async (id) => { + const res = await fetch(`${API_URL}/users/${id}/reset-password`, { + method: 'POST', + headers: getHeaders() + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, + + // Auth Extensions + activateUser: async (token) => { + const res = await fetch(`${API_URL}/auth/activate`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token }) + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, + + forgotPassword: async (email) => { + const res = await fetch(`${API_URL}/auth/forgot-password`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email }) + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, + + resetPassword: async (token, newPassword) => { + const res = await fetch(`${API_URL}/auth/reset-password`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token, newPassword }) + }); + const data = await res.json(); + if (!res.ok) throw new Error(data.error); + return data; + }, // Credits deductCredit: async () => {