0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00
logto/packages/core/src/routes/application.ts

25 lines
630 B
TypeScript
Raw Normal View History

2021-08-14 08:39:37 -05:00
import Router from 'koa-router';
import { nativeEnum, object, string } from 'zod';
import { ApplicationType } from '@logto/schemas';
import koaGuard from '@/middleware/koa-guard';
import koaAuth from '@/middleware/koa-auth';
export default function applicationRoutes(router: Router) {
router.use('/application', koaAuth());
router.post(
'/application',
koaGuard({
body: object({
name: string().min(1),
type: nativeEnum(ApplicationType),
}),
}),
async (ctx, next) => {
const { name, type } = ctx.guard.body;
ctx.body = { name, type };
return next();
}
);
}