diff --git a/src/main/core/api/account/index.ts b/src/main/core/api/account/index.ts index eba0226..3074bdf 100644 --- a/src/main/core/api/account/index.ts +++ b/src/main/core/api/account/index.ts @@ -71,10 +71,10 @@ export async function checkAuth(token: string): Promise { } /** - * Logs in a user with username and password + * Logs in a user with username and password (step-based auth). */ export async function login(request: LoginRequest): Promise { - const res = await fetch(`${API_BASE_URL}/login`, { + const res = await fetch(`${API_BASE_URL}/auth/steps/password`, { method: "POST", headers: getAuthHeaders(null, true), body: JSON.stringify(request) @@ -83,17 +83,28 @@ export async function login(request: LoginRequest): Promise { const error = await res.json().catch(() => ({ detail: "Login failed" })); throw new Error(error.detail || "Login failed"); } - return await res.json(); + const data = await res.json(); + if (data.status === "needs_register") { + throw new Error("Account not found"); + } + return data; } /** - * Registers a new user + * Registers a new user (step-based auth; Yandex proof required when enabled on server). */ -export async function register(request: RegisterRequest): Promise { - const res = await fetch(`${API_BASE_URL}/register`, { +export async function register(request: RegisterRequest & { registration_proof?: string }): Promise { + const res = await fetch(`${API_BASE_URL}/auth/steps/register/confirm`, { method: "POST", headers: getAuthHeaders(null, true), - body: JSON.stringify(request) + body: JSON.stringify({ + display_name: request.display_name, + username: request.username, + password: request.password, + confirm_password: request.confirm_password, + bio: request.bio, + registration_proof: request.registration_proof, + }) }); if (!res.ok) { const error = await res.json().catch(() => ({ detail: "Registration failed" })); diff --git a/src/main/core/api/user/auth.ts b/src/main/core/api/user/auth.ts index 09a7756..91bd483 100644 --- a/src/main/core/api/user/auth.ts +++ b/src/main/core/api/user/auth.ts @@ -70,11 +70,25 @@ export async function checkAuth(token: string): Promise { return await res.json(); } +export interface RegisterConfirmRequest { + display_name: string; + username: string; + password: string; + confirm_password: string; + bio?: string; + registration_proof?: string; +} + +export interface AuthPasswordNeedsRegister { + status: "needs_register"; + yandex_required: boolean; +} + /** - * Logs in a user with username and password + * Logs in a user with username and password (step-based auth). */ export async function login(request: LoginRequest): Promise { - const res = await fetch(`${API_BASE_URL}/login`, { + const res = await fetch(`${API_BASE_URL}/auth/steps/password`, { method: "POST", headers: getAuthHeaders(null, true), body: JSON.stringify(request) @@ -83,17 +97,28 @@ export async function login(request: LoginRequest): Promise { const error = await res.json().catch(() => ({ detail: "Login failed" })); throw new Error(error.detail || "Login failed"); } - return await res.json(); + const data = await res.json(); + if (data.status === "needs_register") { + throw new Error("Account not found"); + } + return data; } /** - * Registers a new user + * Registers a new user (step-based auth; Yandex proof required when enabled on server). */ -export async function register(request: RegisterRequest): Promise { - const res = await fetch(`${API_BASE_URL}/register`, { +export async function register(request: RegisterRequest & { registration_proof?: string }): Promise { + const res = await fetch(`${API_BASE_URL}/auth/steps/register/confirm`, { method: "POST", headers: getAuthHeaders(null, true), - body: JSON.stringify(request) + body: JSON.stringify({ + display_name: request.display_name, + username: request.username, + password: request.password, + confirm_password: request.confirm_password, + bio: request.bio, + registration_proof: request.registration_proof, + }) }); if (!res.ok) { const error = await res.json().catch(() => ({ detail: "Registration failed" })); diff --git a/src/main/core/types.d.ts b/src/main/core/types.d.ts index 16e14af..e068b6e 100644 --- a/src/main/core/types.d.ts +++ b/src/main/core/types.d.ts @@ -182,6 +182,7 @@ export interface RegisterRequest { display_name: string; password: string; confirm_password: string; + bio?: string; } export interface UploadPublicKeyRequest {