48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { API_BASE_URL } from "@config/config_frontend";
|
|
|
|
export interface RegisterPayload {
|
|
email: string;
|
|
password: string;
|
|
name: string;
|
|
account_type: "MASTER" | "MEMBER";
|
|
company_id: number | null;
|
|
company_name: string | null;
|
|
terms_version: string;
|
|
terms_agreed: boolean;
|
|
privacy_agreed: boolean;
|
|
marketing_agreed: boolean;
|
|
}
|
|
|
|
async function request(path: string, body: object): Promise<Record<string, unknown>> {
|
|
const response = await fetch(`${API_BASE_URL}${path}`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
});
|
|
const result = (await response.json()) as Record<string, unknown>;
|
|
if (!response.ok) throw new Error(String(result.detail ?? "Request failed"));
|
|
return result;
|
|
}
|
|
|
|
export function requestRegistration(payload: RegisterPayload): Promise<Record<string, unknown>> {
|
|
return request("/auth/register/request", payload);
|
|
}
|
|
|
|
export function verifyRegistration(
|
|
email: string,
|
|
otpCode: string,
|
|
): Promise<Record<string, unknown>> {
|
|
return request("/auth/register/verify", { email, otp_code: otpCode });
|
|
}
|
|
|
|
export async function searchCompanies(query: string): Promise<{ id: number; name: string }[]> {
|
|
const response = await fetch(`${API_BASE_URL}/auth/companies?q=${encodeURIComponent(query)}`);
|
|
const result = (await response.json()) as {
|
|
detail?: string;
|
|
companies?: { id: number; name: string }[];
|
|
};
|
|
if (!response.ok) throw new Error(result.detail ?? "Request failed");
|
|
return result.companies ?? [];
|
|
}
|