diff --git a/frontend/src/services/.gitkeep b/frontend/src/services/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/frontend/src/services/LoginService.ts b/frontend/src/services/LoginService.ts new file mode 100644 index 00000000..ea2632b1 --- /dev/null +++ b/frontend/src/services/LoginService.ts @@ -0,0 +1,30 @@ +import axios from "axios"; +import apiRoutes from "../routes/routesDefinitions"; +import { LoginAttempt, User } from "../types/User"; + +export default async function postLoginAttempt( + username: string, + password: string +): Promise { + // Create login attempt + const loginAttempt: LoginAttempt = { + username: username, + password: password, + }; + + return await axios + .post(apiRoutes.login, loginAttempt) + .then((res) => { + if (res.status === 200 && res.data.username && res.data.password) { + const user: User = { + username: res.data.username, + password: res.data.password, + }; + return user; + } + }) + .catch((e) => { + console.log(e); + return e.response; + }); +}