Custom plugin Type Error

How do I infer the types for the endpoints to my custom plugin? I'm getting the following type error when calling a custom plugin endpoint. It works, but TypeScript doesn't know the function exists:
Property 'getHelloWorld' does not exist on type 'InferAPI<{ ok: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "GET" | undefined; } & { query?: Record<string, any> | undefined; } & { params?: Record<string, any> | undefined; } & { ...; } & { ...; } & { ...; } & { ...; }) | undefined): ...'.ts(2339)
Property 'getHelloWorld' does not exist on type 'InferAPI<{ ok: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "GET" | undefined; } & { query?: Record<string, any> | undefined; } & { params?: Record<string, any> | undefined; } & { ...; } & { ...; } & { ...; } & { ...; }) | undefined): ...'.ts(2339)
Server auth:
const betterAuthConfig: BetterAuthOptions = {
...otherThings,
plugins: [testPlugin()]
};

export const auth = betterAuth(betterAuthConfig);
const betterAuthConfig: BetterAuthOptions = {
...otherThings,
plugins: [testPlugin()]
};

export const auth = betterAuth(betterAuthConfig);
My custom plugin function:
import { createAuthEndpoint } from 'better-auth/api';
import type { BetterAuthPlugin } from 'better-auth/types';

export const testPlugin = () => {
return {
id: 'test-plugin',
endpoints: {
getHelloWorld: createAuthEndpoint(
'/test-plugin/hello-world',
{
method: 'GET'
},
async (ctx) => {
return ctx.json({
message: 'Hello World'
});
}
)
}
} satisfies BetterAuthPlugin;
};
import { createAuthEndpoint } from 'better-auth/api';
import type { BetterAuthPlugin } from 'better-auth/types';

export const testPlugin = () => {
return {
id: 'test-plugin',
endpoints: {
getHelloWorld: createAuthEndpoint(
'/test-plugin/hello-world',
{
method: 'GET'
},
async (ctx) => {
return ctx.json({
message: 'Hello World'
});
}
)
}
} satisfies BetterAuthPlugin;
};
No description
2 Replies
Ping
Ping2mo ago
It's because you type asserted betterAuthConfig to be BetterAuthOptions, change it to use satisfies instead
Luke
LukeOP2mo ago
That was it, thank you so much!

Did you find this page helpful?