Esscraye
Esscraye
BABetter Auth
Created by Esscraye on 3/20/2025 in #help
additionalFields need defaultValue even for non required field
Hey i have the error that there isn't defaultValue on my field but my fiel has to be not required, and i try to connect using google oauth, on my express app. Can someone help me understand why it says it needs a defaultValue (and i try with or without the line defaultValue: "" but same issue) ? thank you all 😉 here is my auth.ts file :
import { betterAuth } from "better-auth";
import { createPool } from "mysql2/promise";
import {
openAPI,
oAuthProxy,
multiSession,
} from "better-auth/plugins";
import { nextCookies } from "better-auth/next-js";
import { passkey } from "better-auth/plugins/passkey";
import transporter from "./email/nodemailer";
import dotenv from "dotenv";

dotenv.config();

export const auth = betterAuth({
appName: "EPF Projets - API Gateway",
database: createPool({
...
}),
user: {
additionalFields: {
firstName: {
type: "string"
},
sex: {
type: "string",
required: false,
defaultValue: "",
},
phone: {
type: "string",
required: false,
defaultValue: ""
},
address: {
type: "string",
required: false,
defaultValue: ""
},
city: {
type: "string",
required: false,
defaultValue: ""
},
zipCode: {
type: "string",
required: false,
defaultValue: ""
},
country: {
type: "string",
required: false,
defaultValue: ""
},
bio: {
type: "string",
required: false,
defaultValue: ""
}
}
},
...
}
import { betterAuth } from "better-auth";
import { createPool } from "mysql2/promise";
import {
openAPI,
oAuthProxy,
multiSession,
} from "better-auth/plugins";
import { nextCookies } from "better-auth/next-js";
import { passkey } from "better-auth/plugins/passkey";
import transporter from "./email/nodemailer";
import dotenv from "dotenv";

dotenv.config();

export const auth = betterAuth({
appName: "EPF Projets - API Gateway",
database: createPool({
...
}),
user: {
additionalFields: {
firstName: {
type: "string"
},
sex: {
type: "string",
required: false,
defaultValue: "",
},
phone: {
type: "string",
required: false,
defaultValue: ""
},
address: {
type: "string",
required: false,
defaultValue: ""
},
city: {
type: "string",
required: false,
defaultValue: ""
},
zipCode: {
type: "string",
required: false,
defaultValue: ""
},
country: {
type: "string",
required: false,
defaultValue: ""
},
bio: {
type: "string",
required: false,
defaultValue: ""
}
}
},
...
}
2 replies