Initial commit: dashboard
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
apiRequest,
|
||||
clearTokens,
|
||||
setTokens,
|
||||
} from "@/lib/meshkee-api";
|
||||
import type { LoginResponse, MeResponse } from "@/types/auth";
|
||||
|
||||
export async function login(cellNumber: string, password: string) {
|
||||
const data = await apiRequest<LoginResponse>("/auth/login", {
|
||||
method: "POST",
|
||||
body: { cellNumber, password },
|
||||
});
|
||||
|
||||
setTokens(data.accessToken, data.refreshToken);
|
||||
return data;
|
||||
}
|
||||
|
||||
export type RegisterPayload = {
|
||||
cellNumber: string;
|
||||
password: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
email?: string;
|
||||
domain: string;
|
||||
};
|
||||
|
||||
export async function register(payload: RegisterPayload) {
|
||||
const data = await apiRequest<LoginResponse & { requiresOtp?: boolean }>(
|
||||
"/auth/register",
|
||||
{
|
||||
method: "POST",
|
||||
body: payload,
|
||||
},
|
||||
);
|
||||
|
||||
if (data.accessToken && data.refreshToken) {
|
||||
setTokens(data.accessToken, data.refreshToken);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchCurrentUser(signal?: AbortSignal) {
|
||||
return apiRequest<MeResponse>("/auth/me", { auth: true, signal });
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
clearTokens();
|
||||
}
|
||||
Reference in New Issue
Block a user