creating my polls page

This commit is contained in:
Tatiana Nikolaeva 2025-04-28 11:09:38 +05:00
parent 28882e7038
commit 08b22b07c6
16 changed files with 266 additions and 24 deletions

View file

@ -0,0 +1,37 @@
import {BASE_URL, createRequestConfig, handleResponse} from "./BaseApi.ts";
interface IAuthData{
email: string;
password: string;
}
interface IRegistrationData extends IAuthData{
username: string;
firstName: string;
lastName: string;
}
export const registerUser = async (data: IRegistrationData) => {
try{
const response = await fetch(`${BASE_URL}/auth/register`, {
...createRequestConfig('POST'), body: JSON.stringify(data),
})
return await handleResponse(response);
} catch (error){
console.error("Registration error:", error);
throw error;
}
}
export const authUser = async (data: IAuthData) => {
try{
const response = await fetch(`${BASE_URL}/auth/login`, {
...createRequestConfig('POST'), body: JSON.stringify(data),
})
return await handleResponse(response);
}
catch(error){
console.error("Login error:", error);
throw error;
}
}