Skip to content

Commit

Permalink
Fixed Authorization Issue at Signup (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabh7923 authored Oct 16, 2024
1 parent 1c88b98 commit a0d15fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a0d15fb

Please sign in to comment.