Download Amazon-Clone-PERN-stack/server/middleware/authMiddleware.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 650 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/server/middleware/authMiddleware.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/server/middleware/authMiddleware.js
-
curl -L -o authMiddleware.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/server/middleware/authMiddleware.js
650 Bytes
| const jwt = require("jsonwebtoken"); | |
| require("dotenv").config(); | |
| const { SECRET_KEY_FOR_BCRYPT } = process.env; | |
| module.exports = async (req, res, next) => { | |
| try { | |
| const jwtTokenFromClient = req.header("token"); | |
| if (!jwtTokenFromClient) { | |
| return res.status(403).json("Not Authozied"); | |
| } | |
| //jwt.verify compair 'token from client' and secretKeyFrom and if 'jwtTokenFromClient' and 'SECRET_KEY_FOR_BCRYPT' matched the its return payload | |
| const payload = jwt.verify(jwtTokenFromClient, SECRET_KEY_FOR_BCRYPT); | |
| req.user = payload; | |
| next(); | |
| } catch (e) { | |
| console.error(e.message); | |
| return res.status(403).json("Not Authozied"); | |
| } | |
| }; | |