add web ui and user route

This commit is contained in:
2026-02-15 19:29:09 +03:00
parent 8d9b5c32c6
commit 7ced62517a
24 changed files with 3025 additions and 0 deletions

46
web/src/api/auth.ts Normal file
View File

@@ -0,0 +1,46 @@
import { useMutation } from "@tanstack/react-query";
export type LoginData = {
login: string;
password: string;
};
export const useLoginMutation = () => {
return useMutation({
mutationFn: async (data: LoginData) => {
const resp = await fetch("/api/auth/login", {
method: "POST",
body: JSON.stringify(data),
});
return await resp.json();
},
});
};
export type RegisterData = {
login: string;
password: string;
};
export const useRegisterMutation = () => {
return useMutation({
mutationFn: async (data: RegisterData) => {
const resp = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify(data),
});
return await resp.json();
},
});
};
export const useLogoutMutation = () => {
return useMutation({
mutationFn: async () => {
const resp = await fetch("/api/auth/logout", {
method: "POST",
});
return await resp.json();
},
});
};

19
web/src/api/user.ts Normal file
View File

@@ -0,0 +1,19 @@
import { useQuery } from "@tanstack/react-query";
export type User = {
id: number;
login: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
};
export const useUserQuery = () => {
return useQuery({
queryKey: ["user"],
queryFn: async () => {
const resp = await fetch("/api/user");
return (await resp.json()) as User;
},
});
};