feat: add api implementation
This commit is contained in:
25
frontend/src/services/auth.service.ts
Normal file
25
frontend/src/services/auth.service.ts
Normal 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");
|
||||
Reference in New Issue
Block a user