index.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 27
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 3
dl 0
loc 27
ccs 12
cts 13
cp 0.9231
crap 0
rs 10
wmc 6
mnd 2
bc 9
fnc 3
bpm 3
cpm 2
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
B module.exports 0 25 1
1 1
var jwt = require('jsonwebtoken');
2
3 1
module.exports = function(secret) {
4 1
    return function(req, res, next) {
5
        let token;
6 3
        if (req.headers.authorization) {
7
            token = req.headers['authorization'].split(' ')[1];
8
        } else {
9 3
            token = req.body.token || req.query.token || req.headers['x-access-token'];
10
        }
11 3
        if (token) {
12 2
            jwt.verify(token, secret, function(err, decoded) {
13 2
                if (err) {
14 1
                    return res.status(403).send({ success: false, message: 'Failed to authenticate token.' });
15
                } else {
16 1
                    req.decoded = decoded;
17 1
                    next();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
18
                }
19
            });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
20
        } else {
21 1
            return res.status(403).send({
22
                success: false,
23
                message: 'No token provided.'
24
            });
25
        }
26
    }
27
}
28