[GH-ISSUE #938] "role" field is not defined in session.data.user.role #17140

Closed
opened 2026-04-15 15:06:22 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @vedantroy on GitHub (Dec 18, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/938

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

better-auth claims the user does not have a role type -- when it does in practice.

image

Current vs. Expected behavior

Add an optional role field to the user type.

What version of Better Auth are you using?

^1.0.22

Provide environment information

- Chrome
- MacOS (Darwin 24.1.0 arm64 arm)

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

Types

Auth config (if applicable)

export const auth = betterAuth({
    database: new Database(DATABASE_URL),
    plugins: [admin()],
    socialProviders: {
        google: { 
            clientId: process.env.AUTH_GOOGLE_ID as string, 
            clientSecret: process.env.AUTH_GOOGLE_SECRET as string, 
        }, 
    },
    trustedOrigins
})

Additional context

No response

Originally created by @vedantroy on GitHub (Dec 18, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/938 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce better-auth claims the user does not have a role type -- when it does in practice. ![image](https://github.com/user-attachments/assets/ee24a7c3-73d5-4548-8e03-9b7a41d61fd1) ### Current vs. Expected behavior Add an optional `role` field to the user type. ### What version of Better Auth are you using? ^1.0.22 ### Provide environment information ```bash - Chrome - MacOS (Darwin 24.1.0 arm64 arm) ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: new Database(DATABASE_URL), plugins: [admin()], socialProviders: { google: { clientId: process.env.AUTH_GOOGLE_ID as string, clientSecret: process.env.AUTH_GOOGLE_SECRET as string, }, }, trustedOrigins }) ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 15:06:22 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 19, 2024):

make sure you have also added adminClient in your client plugins

<!-- gh-comment-id:2552959801 --> @Bekacru commented on GitHub (Dec 19, 2024): make sure you have also added `adminClient` in your client plugins
Author
Owner

@BenFawley commented on GitHub (Jan 2, 2025):

have you added the inferAdditionalFields to your authClient? This is what mine looks like and I have additional fields on my user with no type errors:

import {
  inferAdditionalFields,
} from "better-auth/client/plugins";

export const authClient = createAuthClient({
  plugins: [
    inferAdditionalFields<typeof auth>(),
  ],
});

https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client

<!-- gh-comment-id:2568458099 --> @BenFawley commented on GitHub (Jan 2, 2025): have you added the inferAdditionalFields to your authClient? This is what mine looks like and I have additional fields on my user with no type errors: ``` import { inferAdditionalFields, } from "better-auth/client/plugins"; export const authClient = createAuthClient({ plugins: [ inferAdditionalFields<typeof auth>(), ], }); ``` https://www.better-auth.com/docs/concepts/typescript#inferring-additional-fields-on-client
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17140