mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 11:05:05 +03:00
Change to new auth endpoints
This commit is contained in:
@@ -71,10 +71,10 @@ export async function checkAuth(token: string): Promise<CheckAuthResponse> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 +83,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" }));
|
||||
|
||||
@@ -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" }));
|
||||
|
||||
Vendored
+1
@@ -182,6 +182,7 @@ export interface RegisterRequest {
|
||||
display_name: string;
|
||||
password: string;
|
||||
confirm_password: string;
|
||||
bio?: string;
|
||||
}
|
||||
|
||||
export interface UploadPublicKeyRequest {
|
||||
|
||||
Reference in New Issue
Block a user