JWKS table: null value in column "alg" violates not-null constraint (Better Auth 1.2.8, PostgreSQL) #1214

Closed
opened 2026-03-13 08:28:38 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @collide-gg on GitHub (May 16, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use the following jwks table schema:
    CREATE TABLE jwks (
    "id" TEXT PRIMARY KEY,
    "alg" TEXT NOT NULL,
    "kid" TEXT NOT NULL,
    "publicKey" TEXT NOT NULL,
    "privateKey" TEXT,
    "createdAt" TIMESTAMP NOT NULL DEFAULT NOW(),
    "updatedAt" TIMESTAMP NOT NULL DEFAULT NOW()
    );
  2. Configure the JWT plugin as recommended:
    jwt({
    jwks: {
    keyPairConfig: {
    alg: "EdDSA",
    crv: "Ed25519"
    }
    }
    })
  3. Trigger any authentication flow that causes key generation.

Current vs. Expected behavior

Expected behavior:
When Better Auth generates and stores a new JWK in the jwks table, the alg (algorithm) and kid (key ID) columns should always be populated with non-null values (e.g., "EdDSA" for alg and a unique string for kid), as required by the schema and JWT/JWK standards.
Current behavior:
Better Auth inserts a new row into the jwks table with alg and kid set to NULL. This violates the NOT NULL constraint on these columns and causes a database error:
[error: null value in column "alg" of relation "jwks" violates not-null constraint]
This prevents user creation and authentication flows from working as intended.

What version of Better Auth are you using?

1.2.8

Provide environment information

Windows 11
Firefox

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { jwt } from "better-auth/plugins";
import { nextCookies } from "better-auth/next-js";
import { sendEmail } from "./email";
import { Pool } from "pg";

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
});

export const auth = betterAuth({
  socialProviders: {
    twitter: {
      clientId: process.env.TWITTER_CLIENT_ID as string,
      clientSecret: process.env.TWITTER_CLIENT_SECRET as string,
    },
  },
  user: {
    modelName: "users",
  },
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: true,
  },
  emailVerification: {
    sendVerificationEmail: async ({ user, url, token }, request) => {
      await sendEmail({
        to: user.email,
        subject: "Verify your email address",
        text: `Click the link to verify your email: ${url}`,
      });
    },
    sendOnSignUp: true,
    autoSignInAfterVerification: true,
  },
  database: pool,
  plugins: [
    jwt({
      jwks: {
        keyPairConfig: {
          alg: "EdDSA",
          crv: "Ed25519"
        }
      }
    }),
    nextCookies(),
  ],
  account: {},
  session: {},
});

Additional context

No response

Originally created by @collide-gg on GitHub (May 16, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use the following jwks table schema: CREATE TABLE jwks ( "id" TEXT PRIMARY KEY, "alg" TEXT NOT NULL, "kid" TEXT NOT NULL, "publicKey" TEXT NOT NULL, "privateKey" TEXT, "createdAt" TIMESTAMP NOT NULL DEFAULT NOW(), "updatedAt" TIMESTAMP NOT NULL DEFAULT NOW() ); 2. Configure the JWT plugin as recommended: jwt({ jwks: { keyPairConfig: { alg: "EdDSA", crv: "Ed25519" } } }) 3. Trigger any authentication flow that causes key generation. ### Current vs. Expected behavior Expected behavior: When Better Auth generates and stores a new JWK in the jwks table, the alg (algorithm) and kid (key ID) columns should always be populated with non-null values (e.g., "EdDSA" for alg and a unique string for kid), as required by the schema and JWT/JWK standards. Current behavior: Better Auth inserts a new row into the jwks table with alg and kid set to NULL. This violates the NOT NULL constraint on these columns and causes a database error: [error: null value in column "alg" of relation "jwks" violates not-null constraint] This prevents user creation and authentication flows from working as intended. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash Windows 11 Firefox ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { jwt } from "better-auth/plugins"; import { nextCookies } from "better-auth/next-js"; import { sendEmail } from "./email"; import { Pool } from "pg"; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); export const auth = betterAuth({ socialProviders: { twitter: { clientId: process.env.TWITTER_CLIENT_ID as string, clientSecret: process.env.TWITTER_CLIENT_SECRET as string, }, }, user: { modelName: "users", }, emailAndPassword: { enabled: true, requireEmailVerification: true, }, emailVerification: { sendVerificationEmail: async ({ user, url, token }, request) => { await sendEmail({ to: user.email, subject: "Verify your email address", text: `Click the link to verify your email: ${url}`, }); }, sendOnSignUp: true, autoSignInAfterVerification: true, }, database: pool, plugins: [ jwt({ jwks: { keyPairConfig: { alg: "EdDSA", crv: "Ed25519" } } }), nextCookies(), ], account: {}, session: {}, }); ``` ### Additional context _No response_
Author
Owner

@dosubot[bot] commented on GitHub (Aug 15, 2025):

Hi, @collide-gg. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that Better Auth 1.2.8 inserts null values into the "alg" and "kid" columns of the jwks table, which violates NOT NULL constraints.
  • This causes database errors during authentication, preventing user creation.
  • The issue persists despite configuring the JWT plugin with the "EdDSA" algorithm.
  • The problem occurs on PostgreSQL using the provided jwks table schema.
  • No further comments or updates have been provided since the initial report.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 15, 2025): Hi, @collide-gg. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that Better Auth 1.2.8 inserts null values into the "alg" and "kid" columns of the jwks table, which violates NOT NULL constraints. - This causes database errors during authentication, preventing user creation. - The issue persists despite configuring the JWT plugin with the "EdDSA" algorithm. - The problem occurs on PostgreSQL using the provided jwks table schema. - No further comments or updates have been provided since the initial report. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1214