Caching user permissions - admin plugin #1307

Closed
opened 2026-03-13 08:32:07 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @axeloehrli on GitHub (Jun 4, 2025).

Is this suited for github?

  • Yes, this is suited for github

Is your feature request related to a problem? Please describe.

Whenever i call the method userHasPermissions of the admin plugin, a request is made to my database, i would like to cache this to improve performance.

// this is not being cached, even if same permissions are provided.
const hasPermisison = await auth.api.userHasPermission({
  body: {
    userId: session?.user.id,
    permissions: permissions,
  },
  });

Describe the solution you'd like

Is there any way we could cache this method, just as we can cache the getSession method using cookieCache?

Describe alternatives you've considered

I tried using the react funcion 'cache' but it doesn't seem to work.

Additional context

No response

Originally created by @axeloehrli on GitHub (Jun 4, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Whenever i call the method userHasPermissions of the admin plugin, a request is made to my database, i would like to cache this to improve performance. ``` // this is not being cached, even if same permissions are provided. const hasPermisison = await auth.api.userHasPermission({ body: { userId: session?.user.id, permissions: permissions, }, }); ``` ### Describe the solution you'd like Is there any way we could cache this method, just as we can cache the getSession method using cookieCache? ### Describe alternatives you've considered I tried using the react funcion 'cache' but it doesn't seem to work. ### Additional context _No response_
Author
Owner

@Kinfe123 commented on GitHub (Jun 7, 2025):

We want to clarify that the APIs we provide are designed to expose core data and functionalities—not to act as a full caching or delivery layer. If your use case requires optimized performance (e.g. SSR or client-heavy apps), you’re encouraged to implement your own cache strategy on top of our APIs. like using redis or sth frameworks specific optimization.

@Kinfe123 commented on GitHub (Jun 7, 2025): We want to clarify that the APIs we provide are designed to expose core data and functionalities—not to act as a full caching or delivery layer. If your use case requires optimized performance (e.g. SSR or client-heavy apps), you’re encouraged to implement your own cache strategy on top of our APIs. like using redis or sth frameworks specific optimization.
Author
Owner

@axeloehrli commented on GitHub (Jun 9, 2025):

Thanks for responding. Just wondering, why is it that the get session method has a cookieCache property, but the user permissions API can't have something similar?

@axeloehrli commented on GitHub (Jun 9, 2025): Thanks for responding. Just wondering, why is it that the get session method has a cookieCache property, but the user permissions API can't have something similar?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1307