additionalFields type not inferred

It doesn't infer any additionalField I add
No description
3 Replies
Moha
Moha2w ago
Look at this comment:
/**
* User schema type used by better-auth, note that it's possible that user could have additional fields
*
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
*/
export type User = z.infer<typeof userSchema>;
/**
* User schema type used by better-auth, note that it's possible that user could have additional fields
*
* todo: we should use generics to extend this type with additional fields from plugins and options in the future
*/
export type User = z.infer<typeof userSchema>;
Source: https://github.com/better-auth/better-auth/blob/canary/packages/core/src/db/schema/user.ts
GitHub
better-auth/packages/core/src/db/schema/user.ts at canary · better...
The most comprehensive authentication framework for TypeScript - better-auth/better-auth
Pietro
PietroOP2w ago
mmh not sure how that helps me? Even if I fix the User type all the typings of methods like auth.api.updateUser would still be broken For now I found a workaround creating a custom plugin:
const userExtraPlugin: () => {
id: 'user-extra';
schema: {
user: {
fields: {
defaultCurrency: {
type: 'string';
};
};
};
};
} = () => {
return {
id: 'user-extra',
schema: {
user: {
fields: {
defaultCurrency: {
type: 'string',
},
},
},
},
};
};
const userExtraPlugin: () => {
id: 'user-extra';
schema: {
user: {
fields: {
defaultCurrency: {
type: 'string';
};
};
};
};
} = () => {
return {
id: 'user-extra',
schema: {
user: {
fields: {
defaultCurrency: {
type: 'string',
},
},
},
},
};
};
this fixes type inference, but it requires that weird duplicated type
Moha
Moha2w ago
Yes, I think that's the only way for now, until they implement the additionalFields in the zod schema

Did you find this page helpful?