idk a lot of changes for the admin stuff

This commit is contained in:
Fishandchips321 2026-03-08 19:30:00 +00:00
parent 2cbbc00489
commit 5251ca6f99
23 changed files with 576 additions and 15 deletions

View file

@ -6,8 +6,51 @@ export interface Session {
expiresOn: string;
}
export interface Login {
username: string;
isAdmin: string;
}
export const logIn = async (username: string, password: string) => {
const response = await axios.post<Session>(`${apiUrl}/auth/login`, `username=${encodeURI(username)}&password=${encodeURI(password)}`);
return response.data;
}
export const GetLoginFromSessonCookie = async () => {
const response = await axios.get<Login>(`${apiUrl}/auth`, { withCredentials: true });
return response.data;
}
export const IsCurrentUserAdmin = async () => {
return (await GetLoginFromSessonCookie()).isAdmin;
}
export const AddUser = async (username: string, password: string, isAdmin: boolean) => {
const response = await axios.post<Login>(`${apiUrl}/auth`, { username: username, password: password, isAdmin: isAdmin }, { withCredentials: true });
return response.data;
}
export const DeleteUser = async (username: string) => {
const response = await axios.delete<Login>(`${apiUrl}/auth`, { data: { username: username }, withCredentials: true });
return response.data;
}
export const GetUserList = async () => {
const response = await axios.get<Array<Login>>(`${apiUrl}/auth/all`, { withCredentials: true });
return response.data;
}
export const GetCurrentUser = async () => {
const resonse = await axios.get<Login>(`${apiUrl}/auth`, { withCredentials: true });
return resonse.data;
}
export const ChangeCurrentUserPassword = async (oldPassword: string, newPassword: string) => {
await axios.put(`${apiUrl}/auth`, { password: oldPassword, newPassword: newPassword }, { withCredentials: true });
}