[PR #430] [CLOSED] Add object type support for database field #3284

Closed
opened 2026-03-13 10:47:00 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/430
Author: @mmikhan
Created: 11/5/2024
Status: Closed

Base: nextHead: main


📝 Commits (2)

  • 413ea60 Add object type support for database field
  • 2e370cf lint fixes

📊 Changes

3 files changed (+30 additions, -9 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+8 -5)
📝 packages/better-auth/src/db/get-migration.ts (+18 -3)
📝 packages/better-auth/src/db/to-zod.ts (+4 -1)

📄 Description

Overview

This PR adds support for storing object type fields in the database across different database engines. It is useful for extending core schema to add a JSON object or even gives the opportunity to add a relationship between the user and other table while still using the user inferring types.

Example Usage

import { betterAuth } from "better-auth";
 
export const auth = betterAuth({
   user: {
      additionalFields: { 
          role: {
             type: "object",
             required: false,
             defaultValue: "{}",
             input: false // don't allow user to set role
          },
      }
   }
})

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/430 **Author:** [@mmikhan](https://github.com/mmikhan) **Created:** 11/5/2024 **Status:** ❌ Closed **Base:** `next` ← **Head:** `main` --- ### 📝 Commits (2) - [`413ea60`](https://github.com/better-auth/better-auth/commit/413ea60348cb2eb6fc2c32b7be401bc1b6291ad7) Add object type support for database field - [`2e370cf`](https://github.com/better-auth/better-auth/commit/2e370cfc56d9bf5e79a6872ed42230e573f51f40) lint fixes ### 📊 Changes **3 files changed** (+30 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+8 -5) 📝 `packages/better-auth/src/db/get-migration.ts` (+18 -3) 📝 `packages/better-auth/src/db/to-zod.ts` (+4 -1) </details> ### 📄 Description ## Overview This PR adds support for storing object type fields in the database across different database engines. It is useful for [extending core schema](https://www.better-auth.com/docs/concepts/database#extending-core-schema) to add a JSON object or even gives the opportunity to add a relationship between the user and other table while still using the user [inferring types](https://www.better-auth.com/docs/concepts/typescript#infering-types). ## Example Usage ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({ user: { additionalFields: { role: { type: "object", required: false, defaultValue: "{}", input: false // don't allow user to set role }, } } }) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 10:47:00 -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#3284