deno.land / x / mongoose@6.7.5 / examples / redis-todo / middleware / auth.js
1234567891011121314151617181920'use strict';
const jwt = require('jsonwebtoken');const JWT_SECRET = require('../config').JWT_SECRET;
module.exports = async function(req, res, next) { try { const authToken = req.header('x-auth'); if (!authToken) return res.status(404).send({ msg: 'AuthToken not found' });
const decodedValue = jwt.verify(authToken, JWT_SECRET); if (!decodedValue) return res.status(401).send({ msg: 'Invalid Authentication' });
req.userId = decodedValue.userId; next(); } catch (err) { res.status(401).send({ msg: 'Invalid Authentication' }); }};
Version Info