fix: login flow
This commit is contained in:
+10
-5
@@ -157,24 +157,29 @@ export type LoginResult =
|
|||||||
// ─── API surface ────────────────────────────────────────────────────────────
|
// ─── API surface ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
// Auth (shared endpoints)
|
// Auth (shared endpoints). The BFF returns the bare User on a completed
|
||||||
|
// login (200), or { otp_required: true } (202) when an emailed code is
|
||||||
|
// needed — there's no { kind } wrapper, so we derive it here.
|
||||||
async login(email: string, password: string): Promise<LoginResult> {
|
async login(email: string, password: string): Promise<LoginResult> {
|
||||||
const { data } = await call<LoginResult>("/auth/login", {
|
const { data } = await call<Me | { otp_required?: boolean }>("/auth/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ email, password }),
|
body: JSON.stringify({ email, password }),
|
||||||
});
|
});
|
||||||
return data;
|
if (data && (data as { otp_required?: boolean }).otp_required) {
|
||||||
|
return { kind: "otp_required" };
|
||||||
|
}
|
||||||
|
return { kind: "session", user: data as Me };
|
||||||
},
|
},
|
||||||
async verifyLoginOtp(
|
async verifyLoginOtp(
|
||||||
email: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
otp: string,
|
otp: string,
|
||||||
): Promise<Me> {
|
): Promise<Me> {
|
||||||
const { data } = await call<{ user: Me }>("/auth/verify-login-otp", {
|
const { data } = await call<Me>("/auth/verify-login-otp", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ email, password, otp }),
|
body: JSON.stringify({ email, password, otp }),
|
||||||
});
|
});
|
||||||
return data.user;
|
return data;
|
||||||
},
|
},
|
||||||
async me(): Promise<Me | null> {
|
async me(): Promise<Me | null> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user