Replace or override baseEndpoints

I want to replace the built in resetPassword endpoint
const authenticator = betterAuth({
plugins: [
{
id: 'plugin',
endpoints: {
resetPassword: createAuthEndpoint(
'/plugin/reset-password',
{
method: 'POST'
},
async ctx => {
return ctx.json({
message: 'reset password'
});
}
)
}
} satisfies BetterAuthPlugin
]
});

// Property 'resetPassword' does not exist on type 'InferAPI...
authenticator.api.resetPassword;
const authenticator = betterAuth({
plugins: [
{
id: 'plugin',
endpoints: {
resetPassword: createAuthEndpoint(
'/plugin/reset-password',
{
method: 'POST'
},
async ctx => {
return ctx.json({
message: 'reset password'
});
}
)
}
} satisfies BetterAuthPlugin
]
});

// Property 'resetPassword' does not exist on type 'InferAPI...
authenticator.api.resetPassword;
If the path is not /reset-password, it gives a type error
const authenticator = betterAuth({
plugins: [
{
id: 'plugin',
endpoints: {
resetPassword: createAuthEndpoint(
'/reset-password',
{
method: 'POST',
body: z.object({
token: z.string(),
newPassword: z.string(),
test: z.string()
})
},
async ctx => {
return ctx.json({
message: 'reset password'
});
}
)
}
} satisfies BetterAuthPlugin
]
});
const data = await authenticator.api.resetPassword({});
const authenticator = betterAuth({
plugins: [
{
id: 'plugin',
endpoints: {
resetPassword: createAuthEndpoint(
'/reset-password',
{
method: 'POST',
body: z.object({
token: z.string(),
newPassword: z.string(),
test: z.string()
})
},
async ctx => {
return ctx.json({
message: 'reset password'
});
}
)
}
} satisfies BetterAuthPlugin
]
});
const data = await authenticator.api.resetPassword({});
If the path is /reset-password it doesn't give a type error, but the return type is still the default { status: boolean }. If I remove body zod schema, data returns { message: string }
3 Replies
bekacru
bekacru3w ago
hmm. so are you saying the return types being affected by weather you provide a body schema or not?
Bill
BillOP3w ago
ya and also the endpoint matter as well
bekacru
bekacru3w ago
the endpoint does matter in the type inference. will take a look about the return type inference being affected by the body schema.

Did you find this page helpful?