diff options
| author | Bobby <[email protected]> | 2022-06-03 16:04:33 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-06-03 16:04:33 +0530 |
| commit | 34407aa326383b641609e1effa39418341b740c0 (patch) | |
| tree | 168a58b40a5f8d33e4854287f9a384408055509b /functions/render.js | |
| parent | 06e4ecd95bfd2817e56af83dbe9af1b6eba283bf (diff) | |
| download | thatcomputerscientist-34407aa326383b641609e1effa39418341b740c0.tar.xz thatcomputerscientist-34407aa326383b641609e1effa39418341b740c0.zip | |
account page
Diffstat (limited to 'functions/render.js')
| -rw-r--r-- | functions/render.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/functions/render.js b/functions/render.js new file mode 100644 index 00000000..84596ca2 --- /dev/null +++ b/functions/render.js @@ -0,0 +1,29 @@ +const jwt = require("jsonwebtoken"); +require("dotenv").config(); +const validationString = process.env.AUTHORIZATION_STRING; +function renderRoute(req, res, page, title, protected = false, data = {}) { + res.locals.messages = req.flash(); + jwt.verify(req.cookies.token, validationString, (err, decoded) => { + if (err) { + res.clearCookie("token"); + if (protected) { + res.redirect("/"); + } else { + res.render(page, { + title: title, + ...data, + }); + } + } else { + res.render(page, { + title: title, + username: decoded.username, + ...data, + }); + } + }); +} + +module.exports = { + renderRoute, +}; |
