deno.land / x / mongoose@6.7.5 / examples / redis-todo / middleware / auth.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'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' }); }};
mongoose

Version Info

Tagged at
a year ago