[GH-ISSUE #2489] additionalFields does not save and is not show it, using authClient.signUp.email({ #9222

Closed
opened 2026-04-13 04:38:04 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @cesarve77 on GitHub (Apr 30, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2489

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Ex

git clone https://github.com/cesarve77/better-auth
cd better-auth
pnpm i
pnpm run dev

click on sign in, fill the form and check the session var, user.role is not present

I am using (client side):

const { data, error } = await authClient.signUp.email({
                email: values.email, 
                password:  values.password, 
                name: values.name,
                role: values.role, // Herei s my question
            }

it is not passing role to the api

I can make it work with database hooks:

export const auth = betterAuth({
    databaseHooks: {
        user: {
            create: {
                before: async (user, ctx) => {
                    return {
                        data: {
                            ...user,
                            role: ctx?.body.role
                        },
                    };
                },
                after: async (user) => {
                    //perform additional actions, like creating a stripe customer
                },
            },
        },
    },

When I do

const {data, error} = await authClient.signIn.email({

data does not bring role value

Current vs. Expected behavior

const { data, error } = await authClient.signUp.email({
                email: values.email, 
                password:  values.password, 
                name: values.name,
                role: values.role, // Herei s my question
            }

Should pass and save user role.
and:

const {data, error} = await authClient.signIn.email({

Should bring role value

What version of Better Auth are you using?

"^1.2.7"

Provide environment information

- MACOS
- Chome

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "sqlite",

    }),
    emailAndPassword: {
        enabled: true
    },

    user: {
        additionalFields: {
            role: {
                type: "string",
                required: true,
                // defaultValue: "user",
                input: false, // don't allow user to set role
                validator: {
                    input: z.enum(["user", "admin"]),
                },
                returned: true,
            },
        }
    }
});

Additional context

inferAdditionalFields

seems not working.
user.role type is not present

Originally created by @cesarve77 on GitHub (Apr 30, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2489 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Ex ``` git clone https://github.com/cesarve77/better-auth cd better-auth pnpm i pnpm run dev ``` click on sign in, fill the form and check the session var, user.role is not present I am using (client side): ``` const { data, error } = await authClient.signUp.email({ email: values.email, password: values.password, name: values.name, role: values.role, // Herei s my question } ``` it is not passing role to the api I can make it work with database hooks: ``` export const auth = betterAuth({ databaseHooks: { user: { create: { before: async (user, ctx) => { return { data: { ...user, role: ctx?.body.role }, }; }, after: async (user) => { //perform additional actions, like creating a stripe customer }, }, }, }, ``` When I do ``` const {data, error} = await authClient.signIn.email({ ``` data does not bring role value ### Current vs. Expected behavior ``` const { data, error } = await authClient.signUp.email({ email: values.email, password: values.password, name: values.name, role: values.role, // Herei s my question } ``` Should pass and save user role. and: ``` const {data, error} = await authClient.signIn.email({ ``` Should bring role value ### What version of Better Auth are you using? "^1.2.7" ### Provide environment information ```bash - MACOS - Chome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "sqlite", }), emailAndPassword: { enabled: true }, user: { additionalFields: { role: { type: "string", required: true, // defaultValue: "user", input: false, // don't allow user to set role validator: { input: z.enum(["user", "admin"]), }, returned: true, }, } } }); ``` ### Additional context inferAdditionalFields seems not working. user.role type is not present
GiteaMirror added the locked label 2026-04-13 04:38:05 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Apr 30, 2025):

For signing up, we use the basic information provided, such as email, password, and other fields that aren't necessarily related to additional values. To set those additional values, you can use the database hooks as you mentioned, and make sure to also reflect them on the client plugin by passing them as part of the plugin configuration like this -

export const authClient = createAuthClient({
  baseURL: "http://localhost:3000",
  fetchOptions: {
    credentials: "include",
  },
  plugins: [inferAdditionalFields<typeof auth>()],
});
<!-- gh-comment-id:2842863433 --> @Kinfe123 commented on GitHub (Apr 30, 2025): For signing up, we use the basic information provided, such as email, password, and other fields that aren't necessarily related to additional values. To set those additional values, you can use the database hooks as you mentioned, and make sure to also reflect them on the client plugin by passing them as part of the plugin configuration like this - ```ts export const authClient = createAuthClient({ baseURL: "http://localhost:3000", fetchOptions: { credentials: "include", }, plugins: [inferAdditionalFields<typeof auth>()], }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9222