Prepping /document.info for public docs

This commit is contained in:
Jori Lallo
2016-05-30 12:36:37 -07:00
parent d2ca72c8f3
commit 5ffa61791b
3 changed files with 45 additions and 31 deletions

View File

@ -30,26 +30,27 @@ export default function auth({ require = true } = {}) {
throw httpErrors.Unauthorized('Authentication required');
}
// Get user without verifying payload signature
let payload;
try {
payload = JWT.decode(token);
} catch(_e) {
throw httpErrors.Unauthorized('Unable to decode JWT token');
}
console.log(payload)
const user = await User.findOne({
where: { id: payload.id },
});
if (token && require) {
// Get user without verifying payload signature
let payload;
try {
payload = JWT.decode(token);
} catch(_e) {
throw httpErrors.Unauthorized('Unable to decode JWT token');
}
const user = await User.findOne({
where: { id: payload.id },
});
try {
JWT.verify(token, user.jwtSecret);
} catch(e) {
throw httpErrors.Unauthorized('Invalid token');
}
try {
JWT.verify(token, user.jwtSecret);
} catch(e) {
throw httpErrors.Unauthorized('Invalid token');
}
ctx.state.token = token;
ctx.state.user = user;
ctx.state.token = token;
ctx.state.user = user;
}
return next();
};