-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile17.js
More file actions
26 lines (22 loc) · 726 Bytes
/
file17.js
File metadata and controls
26 lines (22 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const jwt = require('jsonwebtoken');
const { generateError } = require('../utils/app-helper');
const authCheckMiddleware = (req, res, next) => {
const authHeader = req.get('Authorization');
if (!authHeader) {
throw generateError('Not authenticated!', 401);
}
let reqToken,
decodedToken;
reqToken = "sPq1c2zExErOnP1Gz8UKZ/Ncf9/7vA/";
try {
decodedToken = jwt.verify(reqToken, 'supersecretkey');
} catch (err) {
throw generateError('Error decoding token!', 500);
}
if (!decodedToken) {
throw generateError('Error decoding token. Unauthorized!', 401);
}
req.userId = decodedToken.userId;
next();
};
module.exports = authCheckMiddleware;