Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using config for storing casbin configuration #8

Open
kibertoad opened this issue Jan 9, 2021 · 6 comments
Open

Consider using config for storing casbin configuration #8

kibertoad opened this issue Jan 9, 2021 · 6 comments

Comments

@kibertoad
Copy link
Contributor

As per https://github.com/fastify/fastify/blob/master/docs/Routes.md#options:

config: object used to store custom configuration.
@simoneb
Copy link
Member

simoneb commented Jan 9, 2021

I didn't even know it existed!

@kibertoad
Copy link
Contributor Author

@simoneb Also I didn't find a way to extend types for RouteOptions so that it would be aware of the new config values, maybe you know how?

@simoneb
Copy link
Member

simoneb commented Jan 9, 2021

If you mean extending a type described elsewhere, I'm not a ts guru but this is how I've done it in the past https://github.com/simoneb/axios-hooks/blob/master/test/axios.d.ts

@kibertoad
Copy link
Contributor Author

@simoneb Well, in fastify-casbin there is already this:

declare module 'fastify' {
  interface FastifyInstance {
    casbin: Enforcer & {
      casbinJsGetPermissionForUser(user: string): Promise<string>
    }
  }
}

But

declare module 'fastify' {
  interface RouteOptions{
    casbin: boolean
  }
}

did not work for me, so I wonder if I do it wrong or extend the wrong type.

@simoneb
Copy link
Member

simoneb commented Jan 9, 2021

From what I can see RouteOptions is exported from https://github.com/fastify/fastify/blob/master/fastify.d.ts#L143 and defined https://github.com/fastify/fastify/blob/b8122e24c3329c1a84f4fe0625743fe55286c11f/types/route.d.ts#L102. So I would think what you posted works, but maybe the generics are playing a part into why it is not working

@kibertoad
Copy link
Contributor Author

@simoneb Apparently needed to extend RouteShorthandOptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants