Skip to content

Commit

Permalink
Merge pull request #12 from fga-eps-mds/bugfix/#150-Bug_do_login
Browse files Browse the repository at this point in the history
Bugfix/#150 Resolvendo bug do Login
  • Loading branch information
oEduardoAfonso authored Apr 8, 2021
2 parents f421213 + 57b047a commit 1f80ead
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
10 changes: 3 additions & 7 deletions src/services/authentication/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import React from 'react';

const isAuthenticated = () => {
return (localStorage.getItem('access_token') != null) ? true : false;
}

export async function sendLogin(email, password){
const url = process.env.REACT_APP_API_HOST + "/login";
const body = {
Expand Down Expand Up @@ -32,4 +26,6 @@ export function logOut(){
localStorage.removeItem('access_token', 'student');
}

export default isAuthenticated;
export default function isAuthenticated() {
return (localStorage.getItem('access_token') != null) ? true : false;
};
31 changes: 11 additions & 20 deletions src/views/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ const Content = styled.div`
height: 450px;
width: 400px;
display:flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
Form {
height: 300px;
width: 300px;
margin-top: 60px;
justify-content: space-evenly;
Button{
margin: 0px;
margin-top: 30px;
}
}
`;
Expand Down Expand Up @@ -56,20 +55,16 @@ const Header = ({ children }) => {
}

const Erro = styled.div`
position:absolute;
display: flex;
flex-direction: row;
color:black;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
justify-content: center;
padding-bottom: 5%;
height: 5px;
background: #f3c2c2;
border: 1px solid rgba(255, 245, 157, 0.6);
box-sizing: border-box;
border-radius: 5px;
padding: 8px 5px;
margin-inline: 15px;
box-shadow: 2px 2px grey;
Button{
Expand All @@ -79,8 +74,7 @@ const Erro = styled.div`
box-sizing: border-box;
border-radius: 3px;
padding: 5px 5px;
margin-inline: 15px;
margin-right: 2%;
margin-right: 2px;
}
`

Expand All @@ -96,15 +90,12 @@ export default function Login() {
logOut();
})

function onSubmit(data) {
sendLogin(data.email, data.password);

setTimeout(function () {
if (!isAuthenticated())
createSpanError();
else
history.push("/home");
}, 300);
async function onSubmit(data) {
await sendLogin(data.email, data.password);
if (isAuthenticated())
history.push("/home");
else
createSpanError();
}

function createSpanError() {
Expand Down

0 comments on commit 1f80ead

Please sign in to comment.