Code Duplication    Length = 29-31 lines in 2 locations

v1/models/auth.js 1 location

@@ 259-287 (lines=29) @@
256
    function checkToken(req, res, next) {
257
        var token = req.headers['x-access-token'];
258
259
        if (token) {
260
            jwt.verify(token, jwtSecret, function(err, decoded) {
261
                if (err) {
262
                    return res.status(500).json({
263
                        errors: {
264
                            status: 500,
265
                            source: req.path,
266
                            title: "Failed authentication",
267
                            detail: err.message
268
                        }
269
                    });
270
                }
271
272
                req.user = {};
273
                req.user.api_key = decoded.api_key;
274
                req.user.email = decoded.email;
275
276
                next();
277
            });
278
        } else {
279
            return res.status(401).json({
280
                errors: {
281
                    status: 401,
282
                    source: req.path,
283
                    title: "No token",
284
                    detail: "No token provided in request headers"
285
                }
286
            });
287
        }
288
    }
289
290
    return {

v2/models/auth.js 1 location

@@ 392-422 (lines=31) @@
389
    checkToken: function(req, res, next) {
390
        var token = req.headers['x-access-token'];
391
392
        if (token) {
393
            jwt.verify(token, jwtSecret, function(err, decoded) {
394
                if (err) {
395
                    return res.status(500).json({
396
                        errors: {
397
                            status: 500,
398
                            source: req.path,
399
                            title: "Failed authentication",
400
                            detail: err.message
401
                        }
402
                    });
403
                }
404
405
                req.user = {};
406
                req.user.api_key = decoded.api_key;
407
                req.user.email = decoded.email;
408
409
                next();
410
411
                return undefined;
412
            });
413
        } else {
414
            return res.status(401).json({
415
                errors: {
416
                    status: 401,
417
                    source: req.path,
418
                    title: "No token",
419
                    detail: "No token provided in request headers"
420
                }
421
            });
422
        }
423
    }
424
};
425