MCPcopy Index your code
hub / github.com/Packstack-Tech/packstack / verifyJwt

Function verifyJwt

api/utils/jwt.js:5–23  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

3import models from '../models';
4
5export const verifyJwt = (req) => {
6 return new Promise((resolve, reject) => {
7 const authHeader = req.get('authorization');
8 if (!authHeader) {
9 reject("No auth token provided");
10 }
11
12 try {
13 const token = authHeader.split(' ')[1];
14 const decoded = jwt.verify(token, process.env.JWT_SECRET);
15 models.User.findOne({where: {id: decoded.id}})
16 .then(user => resolve(user))
17 .catch(() => reject("Unable to fetch user."));
18
19 } catch (e) {
20 reject('Invalid auth token');
21 }
22 });
23};
24
25export const authenticate = (req, res, next) => {
26 const authHeader = req.get('authorization');

Callers 1

item.jsFile · 0.90

Calls 1

getMethod · 0.80

Tested by

no test coverage detected