Skip to content

Commit

Permalink
Feat: Add LoginService for handling login attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Jan 4, 2024
1 parent 6de1cc2 commit 6657846
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Empty file removed frontend/src/services/.gitkeep
Empty file.
30 changes: 30 additions & 0 deletions frontend/src/services/LoginService.ts
Original file line number Diff line number Diff line change
@@ -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<User | null> {
// 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;
});
}

0 comments on commit 6657846

Please sign in to comment.