app/middlewares/authenticate.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 22
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 22
rs 10
c 2
b 0
f 0
wmc 4
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 1.3333
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A authenticate.js ➔ ??? 0 18 1
1
const {User} = require('./../models/user');
2
3
let authenticate = (req, res, next) => {
4
    let token = req.header('x-auth');
5
    
6
    User.findByToken(token).then((user) => {
7
        if(!user) {
8
            return Promise.reject();
9
        }
10
        // modify the req object to be used in the route
11
        req.user = user;
12
        req.token = token;
13
        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...
14
    }).catch((err) => {
15
        res.status(401).send({
16
            err,
17
            status : 401
18
        });
19
    });    
20
}
21
22
module.exports = {authenticate};