import axios from "axios" import { apiUrl } from "./api" export interface Session { sessionToken: string; expiresOn: string; } export interface Login { username: string; isAdmin: string; } export const logIn = async (username: string, password: string) => { const response = await axios.post(`${apiUrl}/auth/login`, `username=${encodeURI(username)}&password=${encodeURI(password)}`); return response.data; } export const GetLoginFromSessonCookie = async () => { const response = await axios.get(`${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(`${apiUrl}/auth`, { username: username, password: password, isAdmin: isAdmin }, { withCredentials: true }); return response.data; } export const DeleteUser = async (username: string) => { const response = await axios.delete(`${apiUrl}/auth`, { data: { username: username }, withCredentials: true }); return response.data; } export const GetUserList = async () => { const response = await axios.get>(`${apiUrl}/auth/all`, { withCredentials: true }); return response.data; } export const GetCurrentUser = async () => { const resonse = await axios.get(`${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 }); }