Change to new auth endpoints

This commit is contained in:
2026-07-20 13:42:39 +03:00
Unverified
parent a152a52b03
commit d7ccfef8a8
3 changed files with 51 additions and 14 deletions
+32 -7
View File
@@ -70,11 +70,25 @@ export async function checkAuth(token: string): Promise<CheckAuthResponse> {
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<LoginResponse> {
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<LoginResponse> {
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<LoginResponse> {
const res = await fetch(`${API_BASE_URL}/register`, {
export async function register(request: RegisterRequest & { registration_proof?: string }): Promise<LoginResponse> {
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" }));