Prettify everything

This commit is contained in:
MICHAEL JACKSON
2018-02-17 18:00:56 -08:00
parent d6f2bc089a
commit 2e1f09e913
58 changed files with 1061 additions and 932 deletions

View File

@ -1,41 +1,41 @@
const AuthAPI = require("../AuthAPI")
const AuthAPI = require("../AuthAPI");
const ReadMethods = { GET: true, HEAD: true }
const ReadMethods = { GET: true, HEAD: true };
/**
* Sets req.user from the payload in the auth token in the request.
*/
function userToken(req, res, next) {
if (req.user) {
return next()
return next();
}
const token = (ReadMethods[req.method] ? req.query : req.body).token
const token = (ReadMethods[req.method] ? req.query : req.body).token;
if (!token) {
req.user = null
return next()
req.user = null;
return next();
}
AuthAPI.verifyToken(token).then(
payload => {
req.user = payload
next()
req.user = payload;
next();
},
error => {
if (error.name === "JsonWebTokenError") {
res.status(403).send({
error: `Bad auth token: ${error.message}`
})
});
} else {
console.error(error)
console.error(error);
res.status(500).send({
error: "Unable to verify auth"
})
});
}
}
)
);
}
module.exports = userToken
module.exports = userToken;