Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development-juju' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskisoba committed Nov 23, 2023
2 parents f88aa5b + 1bee60c commit 52efc14
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"host": "127.0.0.1",
"dialect": "mysql"
}
}
}
13 changes: 13 additions & 0 deletions backend/controllers/UserControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ exports.userLogin = async (req, res) => {
}
};

exports.userLogout = async (req, res) => {
try {
const { accessToken } = req.body;
await Users.update(
{ token: null },
{ where: { token: accessToken } }
);
res.json({ message: 'Logout bem-sucedido' });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Erro durante o logout.' });
}
};
1 change: 1 addition & 0 deletions backend/views/routes/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ router.get('/profile', validateToken, (req, res) => {

router.post('/register', userController.userRegister);
router.post('/login', userController.userLogin);
router.post('/logout', userController.userLogout);

module.exports = router;
4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"axios": "^1.6.2",
"formik": "^2.4.5",
"framer-motion": "^10.16.4",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.0"
"web-vitals": "^2.1.0",
"yup": "^1.3.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ const Header = () => {

const handleLogout = async () => {
const accessToken = sessionStorage.getItem("accessToken");

try {
// Chamar o backend para remover o token no banco de dados
await axios.post('http://localhost:3001/auth/logout', { accessToken });

// Remover o token da sessionStorage
sessionStorage.removeItem("accessToken");

// Redirecionar para a página de login
navigate("/login");
} catch (error) {
console.error("Erro ao fazer logout:", error.message);
// Lidar com erros, se necessário
}
};

Expand Down

0 comments on commit 52efc14

Please sign in to comment.