From e619245f1fa83a29a9ec553ef9017871bb5c27c0 Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Wed, 29 Apr 2026 02:07:46 +0300 Subject: add google auth --- src/lib/api/SetPassword.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/lib/api/SetPassword.ts (limited to 'src/lib/api/SetPassword.ts') diff --git a/src/lib/api/SetPassword.ts b/src/lib/api/SetPassword.ts new file mode 100644 index 0000000..ee445fc --- /dev/null +++ b/src/lib/api/SetPassword.ts @@ -0,0 +1,52 @@ +const API_URL = process.env.NEXT_PUBLIC_API_URL; + +export type SetPasswordResponse = + | { data: { success: true }; error: null } + | { data: null; error: { general: string } }; + +export const setPassword = async ( + newPassword: string, + repeatPassword: string, +): Promise => { + try { + const res = await fetch(`${API_URL}/api/users/password/set`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + body: JSON.stringify({ + new_password: newPassword, + repeat_password: repeatPassword, + }), + }); + + const data = await res.json().catch(() => null); + + if (!res.ok) { + const detail = data?.detail; + + return { + data: null, + error: { + general: + typeof detail === 'string' + ? detail + : detail?.msg || 'Ошибка установки пароля', + }, + }; + } + + return { + data: { success: true }, + error: null, + }; + } catch (err: any) { + return { + data: null, + error: { + general: err?.message || 'Network error', + }, + }; + } +}; -- cgit v1.3-3-g829e