JWKs keys are created at each request if you don't manually define the rotationInterval #2362

Closed
opened 2026-03-13 09:47:14 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @spa5k on GitHub (Nov 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Setup latest better auth, and enable the jwt plugin. and if you remove the jwks setup below -

jwt({
      jwt: {
        definePayload: defineJWTPayload,
        issuer: "https://auth.leapocr.com",
        audience: "https://api.leapocr.com",
        expirationTime: "1h",
      },
      // This, so whatever default value is used
      jwks: {
        rotationInterval: 60 * 60 * 24 * 30, // 30 days
        gracePeriod: 60 * 60 * 24 * 30, // 30 days
      },
    }),

will create additional key each request.

Current vs. Expected behavior

It should have suitable default value support out of the box

What version of Better Auth are you using?

1.4.x

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:56 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8132",
    "release": "25.1.0",
    "cpuCount": 10,
    "cpuModel": "Apple M4",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.13 GB"
  },
  "node": {
    "version": "v24.8.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.0"
  },
  "frameworks": [
    {
      "name": "hono",
      "version": "^4.10.6"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    }
  ],
  "betterAuth": {
    "version": "^1.4.1",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
    jwt({
      jwt: {
        definePayload: defineJWTPayload,
        issuer: "https://auth.leapocr.com",
        audience: "https://api.leapocr.com",
        expirationTime: "1h",
      },
      jwks: {
        rotationInterval: 60 * 60 * 24 * 30, // 30 days
        gracePeriod: 60 * 60 * 24 * 30, // 30 days
      },
    }),
});

Additional context

No response

Originally created by @spa5k on GitHub (Nov 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Setup latest better auth, and enable the jwt plugin. and if you remove the jwks setup below - ```ts jwt({ jwt: { definePayload: defineJWTPayload, issuer: "https://auth.leapocr.com", audience: "https://api.leapocr.com", expirationTime: "1h", }, // This, so whatever default value is used jwks: { rotationInterval: 60 * 60 * 24 * 30, // 30 days gracePeriod: 60 * 60 * 24 * 30, // 30 days }, }), ``` will create additional key each request. ### Current vs. Expected behavior It should have suitable default value support out of the box ### What version of Better Auth are you using? 1.4.x ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:56 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8132", "release": "25.1.0", "cpuCount": 10, "cpuModel": "Apple M4", "totalMemory": "32.00 GB", "freeMemory": "0.13 GB" }, "node": { "version": "v24.8.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.0" }, "frameworks": [ { "name": "hono", "version": "^4.10.6" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.7" } ], "betterAuth": { "version": "^1.4.1", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ jwt({ jwt: { definePayload: defineJWTPayload, issuer: "https://auth.leapocr.com", audience: "https://api.leapocr.com", expirationTime: "1h", }, jwks: { rotationInterval: 60 * 60 * 24 * 30, // 30 days gracePeriod: 60 * 60 * 24 * 30, // 30 days }, }), }); ``` ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:47:14 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025):

Thanks for raising this! Currently, if you don’t explicitly set a rotationInterval (and corresponding gracePeriod) in your jwks configuration, the jwt plugin defaults to generating a new key for every request. This behavior occurs because there isn’t a built‑in default value for these fields yet, which is why you’re seeing new keys created each time. As a workaround, you should continue to manually set your jwks config with a proper rotationInterval and gracePeriod (like in your example) to ensure the key remains consistent across requests [1].

Could you confirm whether manually setting these values resolves your issue, or do you need further clarification on any part of the process? tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025): Thanks for raising this! Currently, if you don’t explicitly set a rotationInterval (and corresponding gracePeriod) in your jwks configuration, the jwt plugin defaults to generating a new key for every request. This behavior occurs because there isn’t a built‑in default value for these fields yet, which is why you’re seeing new keys created each time. As a workaround, you should continue to manually set your jwks config with a proper rotationInterval and gracePeriod (like in your example) to ensure the key remains consistent across requests [[1]](https://github.com/better-auth/better-auth/issues/4125). Could you confirm whether manually setting these values resolves your issue, or do you need further clarification on any part of the process? tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@spa5k commented on GitHub (Nov 22, 2025):

for reference, it was not happening before in v1.3.x

@spa5k commented on GitHub (Nov 22, 2025): for reference, it was not happening before in v1.3.x
Author
Owner

@Bekacru commented on GitHub (Nov 22, 2025):

could you try if this is fixed on 1.4.1?

@Bekacru commented on GitHub (Nov 22, 2025): could you try if this is fixed on 1.4.1?
Author
Owner

@goraxe commented on GitHub (Nov 23, 2025):

still happening on 1.4.1

my mistake. I only update the cli package by mistake. Once the actual core package was updated, and rotation / expiration config applied jwks are not getting created per request on 1.4.1

@goraxe commented on GitHub (Nov 23, 2025): ~~still happening on 1.4.1~~ my mistake. I only update the cli package by mistake. Once the actual core package was updated, and rotation / expiration config applied jwks are not getting created per request on 1.4.1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2362