Fix flow errors

This commit is contained in:
Jori Lallo
2017-05-09 23:14:24 -07:00
parent e051713177
commit 75ad27658e
19 changed files with 519 additions and 179 deletions

View File

@@ -1,10 +1,7 @@
import httpErrors from 'http-errors';
import JWT from 'jsonwebtoken';
import {
User,
ApiKey,
} from '../../models';
import { User, ApiKey } from '../../models';
export default function auth({ require = true } = {}) {
return async function authMiddleware(ctx, next) {
@@ -22,8 +19,10 @@ export default function auth({ require = true } = {}) {
}
} else {
if (require) {
throw httpErrors.Unauthorized(`Bad Authorization header format. \
Format is "Authorization: Bearer <token>"\n`);
throw httpErrors.Unauthorized(
`Bad Authorization header format. \
Format is "Authorization: Bearer <token>"\n`
);
}
}
} else if (ctx.body.token) {
@@ -43,9 +42,11 @@ export default function auth({ require = true } = {}) {
// API key
let apiKey;
try {
apiKey = await ApiKey.findOne({ where: {
secret: token,
} });
apiKey = await ApiKey.findOne({
where: {
secret: token,
},
});
} catch (e) {
throw httpErrors.Unauthorized('Invalid api key');
}

View File

@@ -18,7 +18,9 @@ export default function pagination(options) {
offset = isNaN(offset) ? 0 : offset;
if (limit > opts.maxLimit) {
throw httpErrors.BadRequest(`Pagination limit is too large (max ${opts.maxLimit})`);
throw httpErrors.BadRequest(
`Pagination limit is too large (max ${opts.maxLimit})`
);
}
ctx.state.pagination = {
@@ -28,8 +30,9 @@ export default function pagination(options) {
query.limit = ctx.state.pagination.limit;
query.offset = ctx.state.pagination.offset + query.limit;
ctx.state.pagination.nextPath = '/api' + ctx.request.path + '?' + querystring.stringify(query);
ctx.state.pagination.nextPath =
'/api' + ctx.request.path + '?' + querystring.stringify(query);
return next();
}
};
};
}