diff --git a/backend/src/controllers/authController.js b/backend/src/controllers/authController.js index d610812..0eea2ef 100644 --- a/backend/src/controllers/authController.js +++ b/backend/src/controllers/authController.js @@ -49,8 +49,12 @@ exports.login = async (req, res) => { const token = jwt.sign({ name: user.name, isVerified: user.isVerified }, process.env.SECURITY_KEY, { expiresIn: '5hour' }); - res.cookie("token", token); - + const oneWeekInSeconds = 7 * 24 * 60 * 60; // 7 days * 24 hours * 60 minutes * 60 seconds + const expirationDate = new Date(Date.now() + oneWeekInSeconds * 1000); // Convert seconds to milliseconds + res.cookie('token', token, { + expires: expirationDate, + + }); // Send the token in the response res.json({ message: 'Login successful' }); } catch (error) { @@ -202,4 +206,18 @@ exports.facebooklogin = async ( req,res) => { exports.googleLoginApp = async (req,res) => { const { token } = req.body -} \ No newline at end of file +} + + +exports.logout = async (req,res) =>{ + try{ + res.clearCookie('token') + res.json({msg:"Done"}) + } + catch(err){ + res.error(err) + } + +} + + diff --git a/backend/src/routes/authRoutes.js b/backend/src/routes/authRoutes.js index 7e5a749..0fe2b54 100644 --- a/backend/src/routes/authRoutes.js +++ b/backend/src/routes/authRoutes.js @@ -6,5 +6,8 @@ router.post('/login', authController.login); router.post('/googleLogin',authController.googleLogin) router.post('/loginApp', authController.loginApp); router.post('/facebooklogin',authController.facebooklogin); +router.post('/logout', authController.logout); + + module.exports = router; diff --git a/webapp/src/components/UserInfo.js b/webapp/src/components/UserInfo.js index dd0fc33..6be82a0 100644 --- a/webapp/src/components/UserInfo.js +++ b/webapp/src/components/UserInfo.js @@ -1,5 +1,6 @@ import React from 'react' import { Link } from 'react-router-dom' +import { logout } from '../utils/logout' function UserInfo({showProfile}) { return (