[GH-ISSUE #7275] CLI Incorrectly Stringifies JSON Type Defaults in Drizzle #28100

Open
opened 2026-04-17 19:30:05 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @brandon-pereira on GitHub (Jan 11, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7275

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

In the additionalFields property on user, when using Drizzle and Postgres, try to create a type: 'json' field and run @better-auth/cli generate

Example Object:

fieldName: {
  type: "json",
  defaultValue: {
   test: true
  }
},

Current vs. Expected behavior

Current Output: Syntax Error

SyntaxError: ',' expected. (13:53)
  11 |  updatedAt: timestamp('updated_at').defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(),
  12 |  timeZone: text('time_zone').default("America/New_York").notNull(),
> 13 |  customLists: jsonb('test').default([object Object]),

Specifically: > 13 | customLists: jsonb('test').default([object Object]),

Expected Output: No Syntax Error, and a default value that is JSON.

Example:

`customLists: jsonb('test').default({ test: true }),`

See Drizzle JSONB Docs

What version of Better Auth are you using?

0.45.1

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000",
    "release": "25.2.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.37 GB"
  },
  "node": {
    "version": "v22.17.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": [
    {
      "name": "hono",
      "version": "^4.11.3"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.45.1"
    }
  ],
  "betterAuth": {
    "version": "^1.4.10",
    "config": {
      "appName": "BetterDo",
      "emailAndPassword": {
        "enabled": true
      },
      "socialProviders": {
        "google": {
          "clientId": "[REDACTED]",
          "clientSecret": "[REDACTED]"
        }
      },
      "databaseHooks": {
        "user": {
          "create": {},
          "update": {}
        }
      },
      "trustedOrigins": [
        "http://localhost:4000",
        "http://localhost:4001"
      ],
      "plugins": [
        {
          "name": "passkey",
          "config": {
            "id": "passkey",
            "endpoints": {},
            "schema": {
              "passkey": {
                "fields": {
                  "name": {
                    "type": "string",
                    "required": false
                  },
                  "publicKey": {
                    "type": "string",
                    "required": true
                  },
                  "userId": {
                    "type": "string",
                    "references": {
                      "model": "user",
                      "field": "id"
                    },
                    "required": true,
                    "index": true
                  },
                  "credentialID": {
                    "type": "string",
                    "required": true,
                    "index": true
                  },
                  "counter": {
                    "type": "number",
                    "required": true
                  },
                  "deviceType": {
                    "type": "string",
                    "required": true
                  },
                  "backedUp": {
                    "type": "boolean",
                    "required": true
                  },
                  "transports": {
                    "type": "string",
                    "required": false
                  },
                  "createdAt": {
                    "type": "date",
                    "required": false
                  },
                  "aaguid": {
                    "type": "string",
                    "required": false
                  }
                }
              }
            },
            "$ERROR_CODES": {
              "CHALLENGE_NOT_FOUND": "Challenge not found",
              "YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY": "You are not allowed to register this passkey",
              "FAILED_TO_VERIFY_REGISTRATION": "Failed to verify registration",
              "PASSKEY_NOT_FOUND": "Passkey not found",
              "AUTHENTICATION_FAILED": "Authentication failed",
              "UNABLE_TO_CREATE_SESSION": "Unable to create session",
              "FAILED_TO_UPDATE_PASSKEY": "Failed to update passkey"
            }
          }
        }
      ],
      "user": {
        "additionalFields": {
          "timeZone": {
            "type": "string",
            "required": true,
            "defaultValue": "America/New_York"
          },
          "customLists": {
            "type": "json",
            "required": false,
            "defaultValue": "{}"
          },
          "isBeta": {
            "type": "boolean",
            "required": false,
            "defaultValue": false
          },
          "isPushEnabled": {
            "type": "boolean",
            "required": false,
            "defaultValue": false
          },
          "vapidKey": {
            "type": "string",
            "required": false
          }
        }
      }
    }
  }
}

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

Backend, Package

Auth config (if applicable)


Additional context

I tested against canary branch and could replicate - I have a PR for the fix incoming.

Originally created by @brandon-pereira on GitHub (Jan 11, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7275 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce In the `additionalFields` property on user, when using Drizzle and Postgres, try to create a `type: 'json'` field and run `@better-auth/cli generate` Example Object: ```js fieldName: { type: "json", defaultValue: { test: true } }, ``` ### Current vs. Expected behavior Current Output: Syntax Error ``` SyntaxError: ',' expected. (13:53) 11 | updatedAt: timestamp('updated_at').defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()).notNull(), 12 | timeZone: text('time_zone').default("America/New_York").notNull(), > 13 | customLists: jsonb('test').default([object Object]), ``` Specifically: > 13 | `customLists: jsonb('test').default([object Object]),` Expected Output: No Syntax Error, and a default value that is JSON. Example: ``` `customLists: jsonb('test').default({ test: true }),` ``` See [Drizzle JSONB Docs](https://orm.drizzle.team/docs/column-types/pg#jsonb) ### What version of Better Auth are you using? 0.45.1 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000", "release": "25.2.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.37 GB" }, "node": { "version": "v22.17.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": [ { "name": "hono", "version": "^4.11.3" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.45.1" } ], "betterAuth": { "version": "^1.4.10", "config": { "appName": "BetterDo", "emailAndPassword": { "enabled": true }, "socialProviders": { "google": { "clientId": "[REDACTED]", "clientSecret": "[REDACTED]" } }, "databaseHooks": { "user": { "create": {}, "update": {} } }, "trustedOrigins": [ "http://localhost:4000", "http://localhost:4001" ], "plugins": [ { "name": "passkey", "config": { "id": "passkey", "endpoints": {}, "schema": { "passkey": { "fields": { "name": { "type": "string", "required": false }, "publicKey": { "type": "string", "required": true }, "userId": { "type": "string", "references": { "model": "user", "field": "id" }, "required": true, "index": true }, "credentialID": { "type": "string", "required": true, "index": true }, "counter": { "type": "number", "required": true }, "deviceType": { "type": "string", "required": true }, "backedUp": { "type": "boolean", "required": true }, "transports": { "type": "string", "required": false }, "createdAt": { "type": "date", "required": false }, "aaguid": { "type": "string", "required": false } } } }, "$ERROR_CODES": { "CHALLENGE_NOT_FOUND": "Challenge not found", "YOU_ARE_NOT_ALLOWED_TO_REGISTER_THIS_PASSKEY": "You are not allowed to register this passkey", "FAILED_TO_VERIFY_REGISTRATION": "Failed to verify registration", "PASSKEY_NOT_FOUND": "Passkey not found", "AUTHENTICATION_FAILED": "Authentication failed", "UNABLE_TO_CREATE_SESSION": "Unable to create session", "FAILED_TO_UPDATE_PASSKEY": "Failed to update passkey" } } } ], "user": { "additionalFields": { "timeZone": { "type": "string", "required": true, "defaultValue": "America/New_York" }, "customLists": { "type": "json", "required": false, "defaultValue": "{}" }, "isBeta": { "type": "boolean", "required": false, "defaultValue": false }, "isPushEnabled": { "type": "boolean", "required": false, "defaultValue": false }, "vapidKey": { "type": "string", "required": false } } } } } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Package ### Auth config (if applicable) ```typescript ``` ### Additional context I tested against `canary` branch and could replicate - I have a PR for the fix incoming.
GiteaMirror added the devtoolsdatabasebug labels 2026-04-17 19:30:06 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 11, 2026):

It looks like you're facing an issue with the Better Auth CLI incorrectly stringifying JSON type defaults when using Drizzle with Postgres. The expected behavior should allow a JSON default value without resulting in a syntax error, but currently, it outputs a malformed object representation.

There are discussions about similar issues in the GitHub repository, including attempts to fix the output format and handle defaults correctly for the Drizzle schema generation. Notably, recent changes have aimed to improve the handling of schemas and default values in Drizzle [2], [4].

Since you've already tested this against the canary branch and noted this issue, it seems a fix may already be in progress based on related open and closed issues in the repository.

If you have a pull request for the fix incoming, that could greatly help the team address the problem swiftly. For now, keep an eye on the related open issues for updates, and feel free to tag @better-auth-agent for a more direct response or assistance.

What specific features or improvements would you like to see from the CLI moving forward?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3736296222 --> @better-auth-agent[bot] commented on GitHub (Jan 11, 2026): It looks like you're facing an issue with the Better Auth CLI incorrectly stringifying JSON type defaults when using Drizzle with Postgres. The expected behavior should allow a JSON default value without resulting in a syntax error, but currently, it outputs a malformed object representation. There are discussions about similar issues in the GitHub repository, including attempts to fix the output format and handle defaults correctly for the Drizzle schema generation. Notably, recent changes have aimed to improve the handling of schemas and default values in Drizzle [[2]](https://github.com/better-auth/better-auth/pull/1400), [[4]](https://github.com/better-auth/better-auth/pull/3244). Since you've already tested this against the `canary` branch and noted this issue, it seems a fix may already be in progress based on related open and closed issues in the repository. If you have a pull request for the fix incoming, that could greatly help the team address the problem swiftly. For now, keep an eye on the related open issues for updates, and feel free to tag @better-auth-agent for a more direct response or assistance. What specific features or improvements would you like to see from the CLI moving forward? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28100