You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{getMongoRouter}from'./mongo-router'// Example permission check functionasyncfunctionpermissionCheck(ctx: Koa.Context,next: ()=>Promise<any>,database: string,collection: string){// Assumes you have middleware that already adds a userif(ctx.state.user==undefined){ctx.status=401return}// Example of validating if a user has read or write permissionsswitch(ctx.Method){case'GET':
if(!ctx.state.user.canRead(database,collection)){ctx.status=403return}breakcase'PUT':
case'POST':
case'PATCH':
case'DELETE':
if(!ctx.state.user.canWrite(database,collection)){ctx.status=403return}break}// If user haas permission for method, then continue onawaitnext()}constmongoRouter=getMongoRouter({
permissionCheck
})constapp=newKoa().use(mongoRouter.routes()).use(mongoRouter.allowedMethods())