Typescript: plugin registration not showing in auth methods #1329

Closed
opened 2026-03-13 08:32:59 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @gregg-cbs on GitHub (Jun 9, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Register a plugin
  2. The plugin can be accessed via auth.api.myPlugin() but TS showing an error that myPlugin does not exist

Current vs. Expected behavior

Expect the TS types to be update or the documentation to be clear on how to add the plugin type to the auth object.

What version of Better Auth are you using?

1.2.8

Provide environment information

Windows
Nodejs

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

export const guestSessionPlugin = (): BetterAuthPlugin => ({
  id: "guest-session-plugin",
  endpoints: {
    createGuestSession: createAuthEndpoint(
      "/guest-session/create",
      { method: "GET" },
      async (ctx) => {
        // return session data
        return ctx.json({

        });
      }
    ),
  },
});

export function setupAuth() {
  auth = betterAuth({
    database: mongodbAdapter(db_instance),
    trustedOrigins: getOrigins(),
    plugins: [
      guestSessionPlugin(),
    ],
  })

  // ts giving an error (Property 'createGuestSession' does not exist on type 'InferAPI)
  auth.api.createGuestSession()
}

Additional context

No response

Originally created by @gregg-cbs on GitHub (Jun 9, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Register a plugin 2. The plugin can be accessed via auth.api.myPlugin() but TS showing an error that myPlugin does not exist ### Current vs. Expected behavior Expect the TS types to be update or the documentation to be clear on how to add the plugin type to the auth object. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash Windows Nodejs ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const guestSessionPlugin = (): BetterAuthPlugin => ({ id: "guest-session-plugin", endpoints: { createGuestSession: createAuthEndpoint( "/guest-session/create", { method: "GET" }, async (ctx) => { // return session data return ctx.json({ }); } ), }, }); export function setupAuth() { auth = betterAuth({ database: mongodbAdapter(db_instance), trustedOrigins: getOrigins(), plugins: [ guestSessionPlugin(), ], }) // ts giving an error (Property 'createGuestSession' does not exist on type 'InferAPI) auth.api.createGuestSession() } ``` ### Additional context _No response_
Author
Owner

@Kinfe123 commented on GitHub (Jun 9, 2025):

can you try this and follow the docs here for more - https://www.better-auth.com/docs/concepts/plugins

export const guestSessionPlugin = (): BetterAuthPlugin => ({
  id: "guest-session-plugin",
  endpoints: {
    createGuestSession: createAuthEndpoint(
      "/guest-session/create",
      { method: "GET" },
      async (ctx) => {
        // return session data
        return ctx.json({
          // your session data here
        });
      }
    ),
  } satisfies BetterAuthPlugin
});
@Kinfe123 commented on GitHub (Jun 9, 2025): can you try this and follow the docs here for more - https://www.better-auth.com/docs/concepts/plugins ```ts export const guestSessionPlugin = (): BetterAuthPlugin => ({ id: "guest-session-plugin", endpoints: { createGuestSession: createAuthEndpoint( "/guest-session/create", { method: "GET" }, async (ctx) => { // return session data return ctx.json({ // your session data here }); } ), } satisfies BetterAuthPlugin }); ```
Author
Owner

@gregg-cbs commented on GitHub (Jun 10, 2025):

Does not update the types. createGuestSession is still missing from the auth.api. Seems there are a handful of methods that are in the auth.api that TS does not pick up and show.

@gregg-cbs commented on GitHub (Jun 10, 2025): Does not update the types. createGuestSession is still missing from the auth.api. Seems there are a handful of methods that are in the auth.api that TS does not pick up and show.
Author
Owner

@gregg-cbs commented on GitHub (Jun 10, 2025):

What is actually on the auth api (31 methods)
Image

What typescript says there is (25 methods)
Image

@gregg-cbs commented on GitHub (Jun 10, 2025): What is actually on the auth api (31 methods) ![Image](https://github.com/user-attachments/assets/8c86789e-0e67-4251-91ed-45926f98d5de) What typescript says there is (25 methods) ![Image](https://github.com/user-attachments/assets/730ce26e-8682-4e69-aa86-4651e6431275)
Author
Owner

@Kinfe123 commented on GitHub (Jun 12, 2025):

oh i see. can you please use only satisfies .

export const guestSessionPlugin = () => ({
  id: "guest-session-plugin",
  endpoints: {
    createGuestSession: createAuthEndpoint(
      "/guest-session/create",
      { method: "GET" },
      async (ctx) => {
        // return session data
        return ctx.json({
          // your session data here
        });
      }
    ),
  } satisfies BetterAuthPlugin
});

this should work.

@Kinfe123 commented on GitHub (Jun 12, 2025): oh i see. can you please use only satisfies . ```ts export const guestSessionPlugin = () => ({ id: "guest-session-plugin", endpoints: { createGuestSession: createAuthEndpoint( "/guest-session/create", { method: "GET" }, async (ctx) => { // return session data return ctx.json({ // your session data here }); } ), } satisfies BetterAuthPlugin }); ``` this should work.
Author
Owner

@gregg-cbs commented on GitHub (Jun 17, 2025):

I did use that and it didnt work.

Anyways we left better auth for another implementation.

Thank you.

@gregg-cbs commented on GitHub (Jun 17, 2025): I did use that and it didnt work. Anyways we left better auth for another implementation. Thank you.
Author
Owner

@Kinfe123 commented on GitHub (Jun 17, 2025):

May be can try to see if your coding environment is affecting it like TS server or reloading your editor. This is the guide that we have on our docs.

@Kinfe123 commented on GitHub (Jun 17, 2025): May be can try to see if your coding environment is affecting it like TS server or reloading your editor. This is the guide that we have on our docs.
Author
Owner

@hiepxanh commented on GitHub (Jun 21, 2025):

I did use that and it didnt work.

Anyways we left better auth for another implementation.

Thank you.

what do you use instead of better auth? I see it very messy

@hiepxanh commented on GitHub (Jun 21, 2025): > I did use that and it didnt work. > > Anyways we left better auth for another implementation. > > Thank you. what do you use instead of better auth? I see it very messy
Author
Owner

@gregg-cbs commented on GitHub (Jul 7, 2025):

Yeah we ran into tons of issues with Better Auth to the point it was making simple things difficult.

We ended up following https://lucia-auth.com/ - they rolled out an auth like better auth but realised that wrapping auth in an api for public consumption gets messy so instead they deprecated their package and wrote documentation on how to roll your own auth and they give you the code to do so. We swapped out better auth in a day.

My auth api now consists of the following methods:
Image

@gregg-cbs commented on GitHub (Jul 7, 2025): Yeah we ran into tons of issues with Better Auth to the point it was making simple things difficult. We ended up following https://lucia-auth.com/ - they rolled out an auth like better auth but realised that wrapping auth in an api for public consumption gets messy so instead they deprecated their package and wrote documentation on how to roll your own auth and they give you the code to do so. We swapped out better auth in a day. My auth api now consists of the following methods: ![Image](https://github.com/user-attachments/assets/2bd99dd1-e846-4537-bb5d-686a70bd89e0)
Author
Owner

@hiepxanh commented on GitHub (Jul 8, 2025):

Can you share your auth code 🥳🥳🥳 i would like to learn so much

@hiepxanh commented on GitHub (Jul 8, 2025): Can you share your auth code 🥳🥳🥳 i would like to learn so much
Author
Owner

@gregg-cbs commented on GitHub (Jul 8, 2025):

I would love to share it but it would be too much effort to do so.

Read the Lucia docs and along with GPT you can make something nice. You can even give GPT the lucia documentation URL and ask it to reference that to make your auth methods for you.

GPT helped me with setting my cookies and other issues I had along the way and it was very accurate.

And i know it may seem overwhelming but it was pretty easy to do once i got into the groove of it.

@gregg-cbs commented on GitHub (Jul 8, 2025): I would love to share it but it would be too much effort to do so. Read the Lucia docs and along with GPT you can make something nice. You can even give GPT the lucia documentation URL and ask it to reference that to make your auth methods for you. GPT helped me with setting my cookies and other issues I had along the way and it was very accurate. And i know it may seem overwhelming but it was pretty easy to do once i got into the groove of it.
Author
Owner

@hiepxanh commented on GitHub (Jul 9, 2025):

I would love to share it but it would be too much effort to do so.

Read the Lucia docs and along with GPT you can make something nice. You can even give GPT the lucia documentation URL and ask it to reference that to make your auth methods for you.

GPT helped me with setting my cookies and other issues I had along the way and it was very accurate.

And i know it may seem overwhelming but it was pretty easy to do once i got into the groove of it.

Thank for your recommend sir

@hiepxanh commented on GitHub (Jul 9, 2025): > I would love to share it but it would be too much effort to do so. > > Read the Lucia docs and along with GPT you can make something nice. You can even give GPT the lucia documentation URL and ask it to reference that to make your auth methods for you. > > GPT helped me with setting my cookies and other issues I had along the way and it was very accurate. > > And i know it may seem overwhelming but it was pretty easy to do once i got into the groove of it. Thank for your recommend sir
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1329