Admin Plugin - Issue with cookie cache and secondary storage not updating on `auth.api.setRole` call

I'm encountering a problem with cookie cache and secondary storage behavior when updating user roles using auth.api.setRole in my Remix+Better-Auth project.

Issue description:

  • When I call auth.api.setRole to update a user's role (e.g., promote a user to "admin" or revert them), the response headers do not include any Set-Cookie headers. Example response headers look like this:
    { "Content-Type": "application/json" }
  • Because of this, the cookie session does not update on the client side.
  • In my Cloudflare KV store (which is configured as the secondaryStorage for Better-Auth), the user data appears duplicated rather than updated properly. I assume the KV data is supposed to be tied to the session cookie.
  • This leads to inconsistent state where I can promote a user to admin and then when logged in as a "member", change them back to admin again, since cookie cache and secondary storage aren't working properly.
  • Even when I forcibly disable cookie cache like this:
    const session = await auth.api.getSession({
      headers: request.headers,
      query: {
        disableCookieCache: true,
      },
    });

    the problem persists.
Was this page helpful?