Skip to content

Commit

Permalink
added logout button to sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
bryentsariwati committed Apr 22, 2023
1 parent 6aa02ce commit 2ddba8d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/src/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react"
import './nav-bar.css'
import pulse from '../assets/pulse.svg'


const NavBar = (props) => {
return (
<div className='NavBar'>
Expand Down
15 changes: 15 additions & 0 deletions client/src/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ const Dashboard = () => {
setNodeData(traceList[currentTrace]);
}, [currentTrace]);

function logout() {
fetch('/logout', {
method: 'GET',
headers: {
'Content-type': 'application/json',
},
})
.then((response) => {
if(response.status === 200) {
navigate('/');
}
})
}

function Body() {
return (
<div className='body'>
Expand Down Expand Up @@ -109,6 +123,7 @@ const Dashboard = () => {
<button>
<img src={settingsIcon} width='16px'></img>
</button>
<button onClick={()=>logout()}>Logout</button>
</div>
<div id='bodyContent'>
<Body />
Expand Down
1 change: 1 addition & 0 deletions client/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({
'/blahblah': 'http://localhost:3000/',
'/createUser': 'http://localhost:3000/',
'/verifyUser': 'http://localhost:3000/',
'/logout': 'http://localhost:3000/'
},
},
plugins: [react()],
Expand Down
16 changes: 15 additions & 1 deletion server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ const verifyUser = async (req, res, next) => {
}
};

module.exports = { createUser, verifyUser };
const logout = (req,res,next) => {
try {
res.clearCookie("token");
res.sendStatus(200);
} catch(err) {
console.log('Error', err);
let error = {
log: 'Express error handler caught userController.verifyUser',
message: { err: err },
};
return next(error);
}
}

module.exports = { createUser, verifyUser, logout };
7 changes: 7 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ app.get('/api', (req, res) => {
let data = 'hello';
res.status(200).json(data);
});


app.post('/createUser', userController.createUser, jwtController.createJwt, (req, res) => {
console.log('in create user');
res.sendStatus(201);
Expand All @@ -39,6 +41,8 @@ app.post('/verifyUser', userController.verifyUser, jwtController.createJwt, (req
res.sendStatus(200);
});

app.get('/logout', userController.logout);

app.post('/setLogs', redisController.setLogs, (req, res) => {
//successful login
// res.redirect('homepage');
Expand Down Expand Up @@ -68,6 +72,9 @@ app.get('/getLogs', redisController.getLogs, (req, res) => {
// res.redirect('homepage');
res.status(200).json(res.locals.logs);
});



app.get('/getErrLogs', redisController.getErrLogs, (req, res) => {
//successful login
// res.redirect('homepage');
Expand Down

0 comments on commit 2ddba8d

Please sign in to comment.