mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +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> {
|
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",
|
method: "POST",
|
||||||
headers: getAuthHeaders(null, true),
|
headers: getAuthHeaders(null, true),
|
||||||
body: JSON.stringify(request)
|
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" }));
|
const error = await res.json().catch(() => ({ detail: "Login failed" }));
|
||||||
throw new Error(error.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> {
|
export async function register(request: RegisterRequest & { registration_proof?: string }): Promise<LoginResponse> {
|
||||||
const res = await fetch(`${API_BASE_URL}/register`, {
|
const res = await fetch(`${API_BASE_URL}/auth/steps/register/confirm`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: getAuthHeaders(null, true),
|
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) {
|
if (!res.ok) {
|
||||||
const error = await res.json().catch(() => ({ detail: "Registration failed" }));
|
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();
|
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> {
|
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",
|
method: "POST",
|
||||||
headers: getAuthHeaders(null, true),
|
headers: getAuthHeaders(null, true),
|
||||||
body: JSON.stringify(request)
|
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" }));
|
const error = await res.json().catch(() => ({ detail: "Login failed" }));
|
||||||
throw new Error(error.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> {
|
export async function register(request: RegisterRequest & { registration_proof?: string }): Promise<LoginResponse> {
|
||||||
const res = await fetch(`${API_BASE_URL}/register`, {
|
const res = await fetch(`${API_BASE_URL}/auth/steps/register/confirm`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: getAuthHeaders(null, true),
|
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) {
|
if (!res.ok) {
|
||||||
const error = await res.json().catch(() => ({ detail: "Registration failed" }));
|
const error = await res.json().catch(() => ({ detail: "Registration failed" }));
|
||||||
|
|||||||
Vendored
+1
@@ -182,6 +182,7 @@ export interface RegisterRequest {
|
|||||||
display_name: string;
|
display_name: string;
|
||||||
password: string;
|
password: string;
|
||||||
confirm_password: string;
|
confirm_password: string;
|
||||||
|
bio?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadPublicKeyRequest {
|
export interface UploadPublicKeyRequest {
|
||||||
|
|||||||
Reference in New Issue
Block a user