Created
May 13, 2024 16:00
-
-
Save SiddharthManthan/6b37eda292d66b8ba4ae5b4c62734446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jwt = require('jsonwebtoken'); | |
const User = require('../models/User'); | |
const requireAuth = (req, res, next) => { | |
const token = req.cookies.jwt; | |
// Check json web token exists and is verified | |
if(token) { | |
jwt.verify(token, process.env.JWTSECRET, (err, decodedToken) => { | |
if(err) { | |
console.log(err.message); | |
res.redirect('/authentication/signin.html'); | |
return; | |
} else { | |
next(); | |
} | |
}); | |
} else { | |
res.redirect('/authentication/signin.html'); | |
return; | |
} | |
} | |
module.exports = { requireAuth }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment