Linted all middleware.

This commit is contained in:
2018-02-07 13:52:08 +01:00
parent 34982c14fe
commit 58449fc753
2 changed files with 18 additions and 17 deletions

View File

@@ -1,11 +1,11 @@
const mustBeAuthenticated = (req, res, next) => { const mustBeAuthenticated = (req, res, next) => {
if (req.loggedInUser === undefined) {
if (req.loggedInUser === undefined) { return res.status(401).send({
return res.status(401).send({ success: false,
success: false, error: 'You must be logged in.',
error: 'You must be logged in.', });
}); } }
return next(); return next();
}; };
module.exports = mustBeAuthenticated; module.exports = mustBeAuthenticated;

View File

@@ -1,5 +1,6 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
const configuration = require('src/config/configuration').getInstance(); const configuration = require('src/config/configuration').getInstance();
const secret = configuration.get('authentication', 'secret'); const secret = configuration.get('authentication', 'secret');
const Token = require('src/user/token'); const Token = require('src/user/token');
@@ -7,16 +8,16 @@ const Token = require('src/user/token');
// curl -i -H "Authorization:[token]" localhost:31459/api/v1/user/history // curl -i -H "Authorization:[token]" localhost:31459/api/v1/user/history
const tokenToUser = (req, res, next) => { const tokenToUser = (req, res, next) => {
const rawToken = req.headers.authorization; const rawToken = req.headers.authorization;
if (rawToken) { if (rawToken) {
try { try {
const token = Token.fromString(rawToken, secret); const token = Token.fromString(rawToken, secret);
req.loggedInUser = token.user; req.loggedInUser = token.user;
} catch (error) { } catch (error) {
req.loggedInUser = undefined; req.loggedInUser = undefined;
} }
} }
next(); next();
}; };
module.exports = tokenToUser; module.exports = tokenToUser;