Move auth to router.use
This commit is contained in:
@ -8,8 +8,9 @@ import { presentApiKey } from '../presenters';
|
|||||||
import { ApiKey } from '../models';
|
import { ApiKey } from '../models';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
router.use(auth());
|
||||||
|
|
||||||
router.post('apiKeys.create', auth(), async ctx => {
|
router.post('apiKeys.create', async ctx => {
|
||||||
const { name } = ctx.body;
|
const { name } = ctx.body;
|
||||||
ctx.assertPresent(name, 'name is required');
|
ctx.assertPresent(name, 'name is required');
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ router.post('apiKeys.create', auth(), async ctx => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('apiKeys.list', auth(), pagination(), async ctx => {
|
router.post('apiKeys.list', pagination(), async ctx => {
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
const keys = await ApiKey.findAll({
|
const keys = await ApiKey.findAll({
|
||||||
where: {
|
where: {
|
||||||
@ -46,7 +47,7 @@ router.post('apiKeys.list', auth(), pagination(), async ctx => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('apiKeys.delete', auth(), async ctx => {
|
router.post('apiKeys.delete', async ctx => {
|
||||||
const { id } = ctx.body;
|
const { id } = ctx.body;
|
||||||
ctx.assertPresent(id, 'id is required');
|
ctx.assertPresent(id, 'id is required');
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import documents from './documents';
|
|||||||
import views from './views';
|
import views from './views';
|
||||||
import hooks from './hooks';
|
import hooks from './hooks';
|
||||||
import apiKeys from './apiKeys';
|
import apiKeys from './apiKeys';
|
||||||
|
import team from './team';
|
||||||
|
|
||||||
import validation from './middlewares/validation';
|
import validation from './middlewares/validation';
|
||||||
import methodOverride from '../middlewares/methodOverride';
|
import methodOverride from '../middlewares/methodOverride';
|
||||||
@ -64,6 +65,7 @@ router.use('/', documents.routes());
|
|||||||
router.use('/', views.routes());
|
router.use('/', views.routes());
|
||||||
router.use('/', hooks.routes());
|
router.use('/', hooks.routes());
|
||||||
router.use('/', apiKeys.routes());
|
router.use('/', apiKeys.routes());
|
||||||
|
router.use('/', team.routes());
|
||||||
|
|
||||||
// Router is embedded in a Koa application wrapper, because koa-router does not
|
// Router is embedded in a Koa application wrapper, because koa-router does not
|
||||||
// allow middleware to catch any routes which were not explicitly defined.
|
// allow middleware to catch any routes which were not explicitly defined.
|
||||||
|
@ -7,12 +7,13 @@ import auth from './middlewares/authentication';
|
|||||||
import { presentUser } from '../presenters';
|
import { presentUser } from '../presenters';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
router.use(auth());
|
||||||
|
|
||||||
router.post('user.info', auth(), async ctx => {
|
router.post('user.info', async ctx => {
|
||||||
ctx.body = { data: await presentUser(ctx, ctx.state.user) };
|
ctx.body = { data: await presentUser(ctx, ctx.state.user) };
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('user.update', auth(), async ctx => {
|
router.post('user.update', async ctx => {
|
||||||
const { user } = ctx.state;
|
const { user } = ctx.state;
|
||||||
const { name, avatarUrl } = ctx.body;
|
const { name, avatarUrl } = ctx.body;
|
||||||
const endpoint = publicS3Endpoint();
|
const endpoint = publicS3Endpoint();
|
||||||
@ -28,7 +29,7 @@ router.post('user.update', auth(), async ctx => {
|
|||||||
ctx.body = { data: await presentUser(ctx, user) };
|
ctx.body = { data: await presentUser(ctx, user) };
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('user.s3Upload', auth(), async ctx => {
|
router.post('user.s3Upload', async ctx => {
|
||||||
const { filename, kind, size } = ctx.body;
|
const { filename, kind, size } = ctx.body;
|
||||||
ctx.assertPresent(filename, 'filename is required');
|
ctx.assertPresent(filename, 'filename is required');
|
||||||
ctx.assertPresent(kind, 'kind is required');
|
ctx.assertPresent(kind, 'kind is required');
|
||||||
|
@ -6,8 +6,9 @@ import { presentView } from '../presenters';
|
|||||||
import { View, Document } from '../models';
|
import { View, Document } from '../models';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
router.use(auth());
|
||||||
|
|
||||||
router.post('views.list', auth(), async ctx => {
|
router.post('views.list', async ctx => {
|
||||||
const { id } = ctx.body;
|
const { id } = ctx.body;
|
||||||
ctx.assertPresent(id, 'id is required');
|
ctx.assertPresent(id, 'id is required');
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ router.post('views.list', auth(), async ctx => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('views.create', auth(), async ctx => {
|
router.post('views.create', async ctx => {
|
||||||
const { id } = ctx.body;
|
const { id } = ctx.body;
|
||||||
ctx.assertPresent(id, 'id is required');
|
ctx.assertPresent(id, 'id is required');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user