From a0d15fb476449a66738b01ef7f3b1ee40415690b Mon Sep 17 00:00:00 2001 From: Rishabh Yadav <117223377+rishabh7923@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:14:35 +0530 Subject: [PATCH] Fixed Authorization Issue at Signup (#68) --- server/routes/admin.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/routes/admin.js b/server/routes/admin.js index 56f1830..eeccf33 100644 --- a/server/routes/admin.js +++ b/server/routes/admin.js @@ -74,6 +74,7 @@ router.post('/admin', async (req, res, next) => { if (err) { return res.status(500).json({ message: 'Error logging in' }); } + const token = jwt.sign({ userId: user._id }, jwtSecret, { expiresIn: '1h' }); res.cookie('token', token, { httpOnly: true }); return res.redirect('/dashboard'); // Now redirect to dashboard @@ -236,6 +237,10 @@ router.post('/register', async (req, res) => { // Automatically log the user in req.login(user, (err) => { if (err) return res.status(500).json({ message: 'Error logging in after registration' }); + + const token = jwt.sign({ userId: user._id }, jwtSecret, { expiresIn: '1h' }); + res.cookie('token', token, { httpOnly: true }); + return res.redirect('/dashboard'); }); } catch (error) {