Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const jwt = require('jsonwebtoken');
- const config = require('config');
- module.exports = function (req, res, next) {
- const token = req.header('x-auth-token');
- if (!token) return res.status(401).send('Access denied. No token provided.');
- try {
- const decoded = jwt.verify(token, config.get('jwtPrivateKey'));
- req.user = decoded;
- next();
- }
- catch (ex) {
- res.status(400).send('Invalid token.');
- }
- }
- router.post('/', auth, async (req, res) => {
- const { error } = validate(req.body);
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement