oaijs / koa-oai-router

Koa Router, based on OpenAPI, Swagger and Json Schema.
105 stars 15 forks source link

Protected routes #37

Closed werepa closed 7 years ago

werepa commented 7 years ago

How can I protect a specific route using koa-oai-router?

amazing-gao commented 7 years ago

Sorry, i do't known what's the meaning of ”protect“? Disable, invisible or other meanings. Can you offer more detail of protect's behavior? Thank you!

werepa commented 7 years ago

Thanks for listening. I would like to define security routes (JWT, for example). Before I used the following code for this:

app.use(koaJwt({ secret: 'secr3t' }).unless({ path: [/^\/public|] })); // this is not working together with koa-oai-router.

I would like the code to execute a function to check if the user is allowed to access that route.

werepa commented 7 years ago

I found my mistake:

app.use(koaJwt({ secret: 'secr3t' }).unless({ path: [/^\/public|^\/docs-v3|^\/koa-oai-router-v3/] }));

This code fix it.

amazing-gao commented 7 years ago

Ok, that's good.