[PR #5723] fix(jwt): creates a jwk on plugin init #14427

Open
opened 2026-04-13 09:28:12 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5723

State: open
Merged: No


Fixes #5663 by thinking outside the box.

We can check if the jwks table is empty when the plugin is being initialized and add the key pair if needed. Endpoints should not be exposed yet, so this prevents the race condition.

The tests had to be adjusted to run migrations before auth initialization.

Makes #5684 redundant.


Summary by cubic

Prevents the JWKS race by creating and storing a key pair during JWT plugin initialization when the jwks table is empty. Also removes lazy key creation and runs migrations before booting the test instance.

  • Bug Fixes
    • On plugin init, generate and persist a JWK if none exists; throw if a key is missing at runtime.
    • In test utils, run migrations before creating the auth instance (non-MongoDB).

Written for commit 0e26c3c48a. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5723 **State:** open **Merged:** No --- Fixes #5663 by thinking outside the box. We can check if the `jwks` table is empty when the plugin is being initialized and add the key pair if needed. Endpoints should not be exposed yet, so this prevents the race condition. The tests had to be adjusted to run migrations before auth initialization. Makes #5684 redundant. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevents the JWKS race by creating and storing a key pair during JWT plugin initialization when the jwks table is empty. Also removes lazy key creation and runs migrations before booting the test instance. - **Bug Fixes** - On plugin init, generate and persist a JWK if none exists; throw if a key is missing at runtime. - In test utils, run migrations before creating the auth instance (non-MongoDB). <sup>Written for commit 0e26c3c48ac558ead8b239ff99b1ee1ebb0bd2ec. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:28:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#14427