feat: add api implementation

This commit is contained in:
Diego Mireles
2026-05-23 00:07:00 -06:00
parent 3297f3d9fa
commit 39bd572955
12 changed files with 799 additions and 45 deletions

View File

@@ -0,0 +1,25 @@
import { apiFetch, setAuthToken } from "../lib/api";
export interface AuthUser {
id: number;
email: string;
name: string;
}
export const register = (data: { name: string; email: string; password: string }) =>
apiFetch<{ id: number; email: string; name: string }>("/api/auth/register", {
method: "POST",
body: JSON.stringify(data),
});
export const login = async (data: { email: string; password: string }) => {
const res = await apiFetch<{ user: AuthUser; token: string }>("/api/auth/login", {
method: "POST",
body: JSON.stringify(data),
});
setAuthToken(res.token);
return res;
};
export const getMe = () =>
apiFetch<AuthUser & { role: string }>("/api/auth/me");