add web ui and user route
This commit is contained in:
46
web/src/api/auth.ts
Normal file
46
web/src/api/auth.ts
Normal 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
19
web/src/api/user.ts
Normal 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;
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user