260706_1_계정, 로그인, 보안 초안 작성
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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 ?? [];
|
||||
}
|
||||
Reference in New Issue
Block a user