Using Drizzle, do I still need to fill in all the values on `session.additionalFields`?

Do I have to duplicate the config across from drizzle to better-auth, or will drizzle handle it? Specifically: - defaultValue? - fieldName? If I've set drizzle to convert to camel_case internally - references? If I've told drizzle the refs already
additionalFields: {
activeOrganizationId: {
type: "string",
defaultValue: null,
fieldName: "active_organization_id",
references: {
model: "organization",
field: "id",
onDelete: "set null",
},
},
},
additionalFields: {
activeOrganizationId: {
type: "string",
defaultValue: null,
fieldName: "active_organization_id",
references: {
model: "organization",
field: "id",
onDelete: "set null",
},
},
},
8 Replies
SkepticMystic
SkepticMysticOP2mo ago
@Better Auth
Better Auth
Better Auth2mo ago
Hello everyone! I’ve noticed a few common questions coming up about Better Auth, and I’d be happy to clarify some of these points: 1. Setting Up Social Providers:
For example, when using Discord as a social login provider, you need to configure it by importing the provider and supplying your Discord client ID and client secret from the Discord Developer Portal. Make sure you update the redirect URL when switching between local development and production environments [1]. 2. Bot Permissions in Discord OAuth:
Many users have asked about specifying additional bot permissions during the Discord OAuth flow. Recent enhancements allow you to include an optional permissions property that appends a proper permissions parameter to your OAuth URL. This improves flexibility when integrating Discord bots with your authentication flow [2]. 3. Privacy and Email Scope Concerns:
There’s an ongoing discussion regarding the collection of email addresses with Discord sign in. For privacy reasons, some community members prefer avoiding collecting real email addresses and even suggest using the Discord snowflake ID as an alternative. This approach is similar to how some other providers (like Roblox) handle authentication [3]. 4. Handling OAuth URL Formatting Issues:
A frequent issue is the “Invalid OAuth2 redirect_uri” error. Discord’s OAuth URL requires a “++” prefix before the redirect_uri parameter. Ensure that your Better Auth configuration generates OAuth URLs with this prefix to meet Discord’s requirements and prevent authentication errors [5]. 5. Avoiding Repeated Authorization Prompts:
Users have noted
GitHub
Build software better, together
GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Better Auth
Better Auth2mo ago
that Discord might prompt for authorization every time they sign in—even after the first successful login. Discord supports a “prompt” parameter in the OAuth request, and setting it appropriately (for example, to “none” by default) can help create a smoother experience, similar to what’s observed with other providers like GitHub [15]. I hope these explanations help clear up some of the common questions our community has been asking. If you have more specific issues or further questions about Better Auth, feel free to ask! Sources: [1] Discord | Better Auth [2] feat: add Discord bot permissions parameter support [3] feat: Discord Oauth without the email scope [5] Discord OAuth redirect_uri requires double plus signs (++) prefix - Better Auth generates invalid URLs [15] Discord login always prompts for authorization
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Discord | Better Auth
Discord provider setup and usage.
GitHub
feat: add Discord bot permissions parameter support by TheUntraceab...
When using the Discord social plugin, you can set the bot scope, and this scope can have an additional permissions scope, referring to the permissions of the Discord Bot once authorized. This pull ...
GitHub
feat: Discord Oauth without the email scope · Issue #2059 · bette...
Is this suited for github? Yes, this is suited for github Is your feature request related to a problem? Please describe. I find collecting email addresses a potential privacy concern depending on t...
GitHub
Discord OAuth redirect_uri requires double plus signs (++) prefix -...
Is this suited for github? Yes, this is suited for github To Reproduce Create Expo app with Better Auth Configure Better Auth with Discord OAuth provider Set redirect URL in Discord Developer Dashb...
SkepticMystic
SkepticMysticOP2mo ago
@Better Auth Do I have to duplicate the config across from drizzle to better-auth, or will drizzle handle it? Specifically: - defaultValue? - fieldName? If I've set drizzle to convert to camel_case internally - references? If I've told drizzle the refs already
additionalFields: {
activeOrganizationId: {
type: "string",
defaultValue: null,
fieldName: "active_organization_id",
references: {
model: "organization",
field: "id",
onDelete: "set null",
},
},
},
additionalFields: {
activeOrganizationId: {
type: "string",
defaultValue: null,
fieldName: "active_organization_id",
references: {
model: "organization",
field: "id",
onDelete: "set null",
},
},
},
Better Auth
Better Auth2mo ago
When you configure Better Auth’s additionalFields, you need to include these settings (defaultValue, fieldName, references, etc.) in the Better Auth config because Better Auth does not automatically “inherit” them from your drizzle settings. In other words, even if drizzle is set up to convert your field names or manage references, you must duplicate (or rather, align) these configurations in your Better Auth config so that its CLI and adapter can generate the correct schema and validations. For example: • The defaultValue in Better Auth’s additionalFields needs to be provided explicitly. There have been issues where the CLI generated the default incorrectly if it wasn’t properly set, so having it defined in your auth config (and matching what your drizzle schema expects) is important [1], [5]. • The fieldName option in additionalFields is also necessary—even if drizzle is set to convert fields to a particular casing (like snake_case)—because Better Auth uses your config to map user inputs to the database columns. Without it, you might run into errors or mismatches, as seen in some reported issues [1], [8]. • Similarly, the references setting in Better Auth’s config must be specified. Even though your drizzle schema already includes foreign key references, Better Auth needs that information from its own config to correctly perform validations and generate the schema [1]. So overall, to ensure consistency and proper behavior, it’s best to duplicate (i.e. re-specify) these settings in your Better Auth configuration rather than relying solely on the drizzle adapter’s internal
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
GitHub
better-auth/better-auth
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Better Auth
Better Auth2mo ago
GitHub
bug: defaultValue in additionalFields does not work for drizzle · ...
Is this suited for github? Yes, this is suited for github To Reproduce define user and set an additional fields with a default value for drizzle npx @better-auth/cli generate the generated schema d...
GitHub
Cli Generate Additional Fields Incorrectly Generates Default Value ...
Is this suited for github? Yes, this is suited for github To Reproduce Create auth.ts import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/d...
GitHub
fieldName causes blank fields when getting session · Issue #1968 ...
Is this suited for github? Yes, this is suited for github To Reproduce When having fieldName setup in certain way it messes with drizzle adapter query resulting in field being always undefined. Set...
SkepticMystic
SkepticMysticOP2mo ago
Makes sense. Can a human please verify this though, if you know
Ping
Ping2mo ago
default value will be applied automatically via better-auth, no schema needed for this, other than that if you run the better-auth CLI it should apply references & the field names to the generated schema

Did you find this page helpful?