User type after adding additional fields to user

Hey, After adding an additional field to the user in the be and add the plugin in the fe to make it work, i encountered a bug relating to the User type. So if i take the user from the useSession, i can see that that description is in there while hovering but if i try to type it with the User from better-auth/types, it is not there. Thanks in advance 🙂
2 Replies
bekacru
bekacru6d ago
Yeah you should use auth.$infer.Session to infer both session and user type
STVN
STVNOP6d ago
Oh nice, I’ll try that, thanks 🙏🏻 @bekacru, I saw that there were AdditionalUserFieldsOutput type, should i use this ? And if yes, is there documentation for this ? I found a solution if someone is interested:
import type {
AdditionalUserFieldsOutput,
BetterAuthOptions,
User,
} from "better-auth/types"

interface AdditionalUserFields extends BetterAuthOptions {
user: {
additionalFields: {
description: {
type: "string"
required: false
defaultValue: string
}
}
}
}

export type UpdatedUser = User &
AdditionalUserFieldsOutput<AdditionalUserFields>
import type {
AdditionalUserFieldsOutput,
BetterAuthOptions,
User,
} from "better-auth/types"

interface AdditionalUserFields extends BetterAuthOptions {
user: {
additionalFields: {
description: {
type: "string"
required: false
defaultValue: string
}
}
}
}

export type UpdatedUser = User &
AdditionalUserFieldsOutput<AdditionalUserFields>

Did you find this page helpful?