The additional user fields should be available in the sendVerificationEmail and sendResetPassword functions. #406

Closed
opened 2026-03-13 07:44:39 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @bfovez on GitHub (Dec 15, 2024).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

export const auth = betterAuth({
	database: new Pool({ connectionString: url }),
	user: {
		additionalFields: {
			locale: {   // <--- the locale additonal user field here...
				type: 'string', 
				required: true
			}
		}
	},

	emailVerification: {
		sendOnSignUp: true,
		autoSignInAfterVerification: true,
		sendVerificationEmail: async ({ user }) => {
			console.log(user.locale) //  <--- ...is not available there. (typescript error)
		}
	}
})

image

Current vs. Expected behavior

The additional user fields should be available in the sendVerificationEmail and sendResetPassword functions.

What version of Better Auth are you using?

1.0.20

Provide environment information

Windows 11
Node v20.11.1

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"

export const auth = betterAuth({
	database: new Pool({ connectionString: url }),
	user: {
		additionalFields: {
			locale: {   // <--- the locale additonal user field here...
				type: 'string', 
				required: true
			}
		}
	},

	emailVerification: {
		sendOnSignUp: true,
		autoSignInAfterVerification: true,
		sendVerificationEmail: async ({ user }) => {
			console.log(user.locale) //  <--- ...is not available there. (typescript error)
		}
	}
})

Additional context

No response

Originally created by @bfovez on GitHub (Dec 15, 2024). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce ```ts export const auth = betterAuth({ database: new Pool({ connectionString: url }), user: { additionalFields: { locale: { // <--- the locale additonal user field here... type: 'string', required: true } } }, emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user }) => { console.log(user.locale) // <--- ...is not available there. (typescript error) } } }) ``` ![image](https://github.com/user-attachments/assets/b2377660-31db-4cda-9ae6-9b888653ee5e) ### Current vs. Expected behavior The additional user fields should be available in the `sendVerificationEmail `and `sendResetPassword `functions. ### What version of Better Auth are you using? 1.0.20 ### Provide environment information ```bash Windows 11 Node v20.11.1 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: new Pool({ connectionString: url }), user: { additionalFields: { locale: { // <--- the locale additonal user field here... type: 'string', required: true } } }, emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user }) => { console.log(user.locale) // <--- ...is not available there. (typescript error) } } }) ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 07:44:39 -05:00
Author
Owner

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

This is because we are unable to infer the type, as typescript does not allow type inference within the same object tree. But, it should be a union with Record<string, any> to account for that, at least for the time being.

@Bekacru commented on GitHub (Dec 16, 2024): This is because we are unable to infer the type, as typescript does not allow type inference within the same object tree. But, it should be a union with `Record<string, any>` to account for that, at least for the time being.
Author
Owner

@grosenberg commented on GitHub (Jan 9, 2025):

This seems to work:

export type User = typeof auth.$Infer.Session.user;
...
     sendVerificationEmail: async ({ user, url, token }, request) => {
         const u = user as User;
         // verify no TS error on referencing the additionalFields
         const locale = u.locale;
         await sendMyVerificationEmail(u, url);
     }
@grosenberg commented on GitHub (Jan 9, 2025): This seems to work: export type User = typeof auth.$Infer.Session.user; ... sendVerificationEmail: async ({ user, url, token }, request) => { const u = user as User; // verify no TS error on referencing the additionalFields const locale = u.locale; await sendMyVerificationEmail(u, url); }
Author
Owner

@bfovez commented on GitHub (Jan 10, 2025):

Thanks!

Le jeu. 9 janv. 2025 à 20:37, Gerald Rosenberg @.***> a
écrit :

This seems to work:

export type User = typeof auth.$Infer.Session.user;
...
sendVerificationEmail: async ({ user, url, token }, request) => {
const u = user as User;
// verify no TS error on referencing the additionalFields
const locale = u.locale;
await sendMyVerificationEmail(u, url);
}


Reply to this email directly, view it on GitHub
https://github.com/better-auth/better-auth/issues/897#issuecomment-2581106295,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEUCQ4FN7K7PG3MPT5IGYDL2J3FWTAVCNFSM6AAAAABTUSH5C2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBRGEYDMMRZGU
.
You are receiving this because you authored the thread.Message ID:
@.***>

@bfovez commented on GitHub (Jan 10, 2025): Thanks! Le jeu. 9 janv. 2025 à 20:37, Gerald Rosenberg ***@***.***> a écrit : > This seems to work: > > export type User = typeof auth.$Infer.Session.user; > ... > sendVerificationEmail: async ({ user, url, token }, request) => { > const u = user as User; > // verify no TS error on referencing the additionalFields > const locale = u.locale; > await sendMyVerificationEmail(u, url); > } > > — > Reply to this email directly, view it on GitHub > <https://github.com/better-auth/better-auth/issues/897#issuecomment-2581106295>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AEUCQ4FN7K7PG3MPT5IGYDL2J3FWTAVCNFSM6AAAAABTUSH5C2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBRGEYDMMRZGU> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@budivoogt commented on GitHub (Jun 26, 2025):

This seems to work:

export type User = typeof auth.$Infer.Session.user;
...
     sendVerificationEmail: async ({ user, url, token }, request) => {
         const u = user as User;
         // verify no TS error on referencing the additionalFields
         const locale = u.locale;
         await sendMyVerificationEmail(u, url);
     }

This is helpful, thank you.

@budivoogt commented on GitHub (Jun 26, 2025): > This seems to work: > > ``` > export type User = typeof auth.$Infer.Session.user; > ... > sendVerificationEmail: async ({ user, url, token }, request) => { > const u = user as User; > // verify no TS error on referencing the additionalFields > const locale = u.locale; > await sendMyVerificationEmail(u, url); > } > ``` This is helpful, thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#406