Created
May 13, 2024 16:00
-
-
Save SiddharthManthan/6b37eda292d66b8ba4ae5b4c62734446 to your computer and use it in GitHub Desktop.
Revisions
-
SiddharthManthan created this gist
May 13, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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 };