54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { apiRequest } from "./client";
|
|
|
|
import type {
|
|
ApiCustomer,
|
|
LoginPayload,
|
|
QuickLoginPayload,
|
|
QuickSignupPayload,
|
|
SignupPayload,
|
|
} from "../types";
|
|
|
|
const CUSTOMER_BASE = "/api/customer";
|
|
|
|
export function signup(payload: SignupPayload) {
|
|
return apiRequest<ApiCustomer>(`${CUSTOMER_BASE}/signup`, {
|
|
method: "POST",
|
|
body: payload,
|
|
});
|
|
}
|
|
|
|
export function quickSignup(payload: QuickSignupPayload) {
|
|
return apiRequest<ApiCustomer>(`${CUSTOMER_BASE}/quick_signup`, {
|
|
method: "POST",
|
|
body: payload,
|
|
});
|
|
}
|
|
|
|
export function login(payload: LoginPayload) {
|
|
return apiRequest<ApiCustomer>(`${CUSTOMER_BASE}/login`, {
|
|
method: "POST",
|
|
body: payload,
|
|
});
|
|
}
|
|
|
|
export function quickLogin(payload: QuickLoginPayload) {
|
|
return apiRequest<ApiCustomer>(`${CUSTOMER_BASE}/quick_login`, {
|
|
method: "POST",
|
|
body: payload,
|
|
});
|
|
}
|
|
|
|
export function me() {
|
|
return apiRequest<ApiCustomer>(CUSTOMER_BASE, { method: "GET" });
|
|
}
|
|
|
|
export function logout() {
|
|
// Backend has no logout endpoint; clearing the httpOnly `auth` cookie
|
|
// requires a server-side Set-Cookie with Max-Age=0. Until the gateway
|
|
// exposes /logout, we trigger an invalid-auth response by calling /me
|
|
// with a fresh client after clearing browser-accessible state.
|
|
// The auth cookie is httpOnly so we cannot remove it from JS; the
|
|
// server must do it. For now this is a no-op network call.
|
|
return Promise.resolve();
|
|
}
|