Skip to content

Commit

Permalink
Merge branch 'main' into issue-245
Browse files Browse the repository at this point in the history
  • Loading branch information
Alecell authored Jul 25, 2024
2 parents 21ae35a + b61ba61 commit 8faa234
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"login": [
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc3OTFkZmMwLWY3YzEtNDAyMy05ZDUxLTFlYTQ3OWQ2ZjgyYiIsIm5hbWUiOiJqb2huZG9lQGV4YW1wbGUuY29tIiwiZW1haWwiOiJqb2huZG9lQGV4YW1wbGUuY29tIiwiZXhwIjoxNzIxODI4MDA3fQ.Agk6Yz2E6TpoqI6mVYeClKx1zOxSsp TyIhtJEvFvG-E"
}
],
"user": [
{
"id": "1",
Expand Down
22 changes: 22 additions & 0 deletions src/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@ export const UserService = {
return `Ocorreu o seguinte erro: ${error}`;
}
},
login: async (email, password) => {
try {
const response = await fetch(`${url}/login`, {
method: 'POST',
body: JSON.stringify({ email, password }),
});

if (!response.ok) throw new Error('Failed to login');

const { token } = await response.json();
return {
success: true,
token,
};
} catch (error) {
console.error(`An error occurred: ${error}`);
return {
success: false,
message: error.message,
};
}
},
};

0 comments on commit 8faa234

Please sign in to comment.