Issue with monorepo setups

It doesn't seem possible to use a default config and export to multiple apps while maintaining type inference (i.e. loses additional fields etc.). Is there something I'm doing wrong or is it just not implemented to work like that? Also, if I try to return without explicitly setting the return value as "BetterAuthOptions" it gives this error: The inferred type of 'getAuthDefaults' cannot be named without a reference to '../nodemodules/better-auth/dist/shared/better-auth.Bzjh9zg'. This is likely not portable. A type annotation is necessary.ts(2742) The inferred type of 'getAuthDefaults' cannot be named without a reference to '../node_modules/better-auth/dist/shared/better-auth.Cl08k4BO'. This is likely not portable. A type annotation is necessary.ts(2742) On the client side, I am adding "inferAdditionalFields<typeof auth>()" to my plugins array as described in the docs - and it works if I copy and paste the default config into the app specific better auth config directly, but then fails to infer if I import it and spread it into it Below seems to be related to my issue: https://github.com/better-auth/better-auth/issues/2123
GitHub
The inferred type of 'auth' cannot be named without a reference · ...
Is this suited for github? Yes, this is suited for github To Reproduce setup better-auth in express node application. Current vs. Expected behavior The inferred type of &#39;auth&#39; cannot be nam...
3 Replies
whizzy
whizzy3mo ago
this generally happens in mono repos you have to fix you tsconfig
DN_Dev
DN_DevOP3mo ago
I generally don't like the work arounds for this kind of issue. Anyway, I was able to fix it by splitting up the default config into smaller, separate objects like so: export const BETTER_AUTH_DEFAULT_EMAIL_AND_PASSWORD = { enabled: true, autoSignIn: false, disableSignUp: false, requireEmailVerification: true, minPasswordLength: PASSWORD_MIN_LENGTH, maxPasswordLength: PASSWORD_MAX_LENGTH, resetPasswordTokenExpiresIn: TOKEN_VALID_FOR_PERIOD_IN_SECS, } satisfies BetterAuthOptions["emailAndPassword"]; And now type inference works as expected
whizzy
whizzy3mo ago
gotcha makes sense I guess in mono repos, things always have problems

Did you find this page helpful?