Better Auth

BA

Better Auth

Join the community to ask questions about Better Auth and get answers from other members.

Join

bug-reports

help

activeOrganizationId stays null after setActiveOrganization

Creating org + setting as active works, but session.activeOrganizationId remains null on next request. Create org: ```ts const orgData = await auth.api.createOrganization({ body: {...
Solution:
Do you use cookie cache?

@better-auth/cli ZOD version dependency

Hey all, The @better-auth/cli ZOD peer dependency is currently set to the following. Should this not have a ^ in front of the v3? ...

Bearer 2FA

I’m using bearer plugin for auth flow because of tauri mobile app. Default login are working fine when I receive a token - just put it inside localstorage and that’s all. Problem is when I need to sign in with TOTP enabled, after sign-in I receive ‘twoFactorEnabled’ and requesting a TOTP code but I cannot verify it because token that we have not linked to any session yet. I see some other cookies that I can’t use because of tauri cookie limitation such as 2fa, don’t remember and other. @Better Auth can you please provide a doc link where defined flow of not using any cookies but having 2fa, trust device, remember me features working?...

Next-intl + Stripe

Has anyone had an issue where a calling authClient.subscription.upgrade eventually leads to a localized api endpoint? I figure directly after processing in /api/auth/subscription/upgrade there's a call that's redirected to a localization, but I can't seem to figure out how to fix it (ps I've already tweaked my middleware.ts)

Additional fields, FAILED_TO_CREATE_USER

I have a issue, I have some custom fields and I want to pass them on user creation, but seems to get FAILED_TO_CREATE_USER, with no details more about the error.

Problem generate models with bun (bunx)

``` ❯ bunx @better-auth/cli generate node:internal/modules/esm/resolve:274 throw new ERR_MODULE_NOT_FOUND( ^...

MCP plugin: problems with oauth and how to show consent screen to user

I implemented according to the mcp plugin docs but I cannot add it as a custom connector in Claude Desktop. Neither the localhost nor a version hosted on vercel. When I disable auth / oauth it works seamlessly and all the tools load and work. A guess would be because of the protected-ressource-metadata that is not inplemented according to the docs?...

Waterfall in custom session plugin

So currently I am using customSessionPlugin to decorate my session. I have user_preferences schema, that has 1:1 realtionship with user. This create waterfall chain first session-> user->user_preferences. The waterfall between session and user makes absolute sense but I was wondering if we could avoid waterfall between user and user_preferences. I was going through code of fetchSession and it seems this is not possible in better-auth. Has anyone tackled this before? Any workarounds or patterns you've adopted would be super helpful!...

better-auth+prisma+mongodb combo literally doesn't work

When the psiam.schema is generated using the better auth cli generate command, I was surprised that all the ids didn't have the @db.ObjectId I ignored that at first glance, but then I hit a wall where I literally can't work anymore.. in my user/[id] page I have a server action that fetches the user by id with prisma. The id is right but I get this issue ...
Solution:
I found this solution: Solution: 1- in auth.ts add the following:...
No description

Hierarchically nested teams

Goal: Get organization with proper hierarchical structure. There is top level team that has more teams (departments) bellow, bellow that departments there is even more teams. Is something like that possible with Nest.js via adding custom field?

How can i prevent same phone number adding by other user?

I can see same phone number can be added by other email account as well. how to prevent this? some check needed like number already used or unique number. sms credit is wasting simply...

Metadata on subscriptions not working.

```typescript const { error: upgradeError } = await authClient.subscription.upgrade({ plan, successUrl, cancelUrl,...

OTP immediately expires after creating

Hi Better Auth team, I’m running into a persistent issue with OTPs in my project. Whenever a user signs up or requests an OTP: I am using password & email plugin to sign-up user, then we use that email to send a verification email. We also have the Email OTP plugin configured. AuthClient.signUp.email(...)then authClient.emailOtp.sendVerificationOtp(...). We use authClient.emailOtp.verifyEmail(...) to verify the email. ...

How to enforce max active sessions in Next.js with better-auth?

Hey, I’m using Next.js with better-auth (Drizzle ORM + Postgres, Google OAuth only) and I want to implement a max active session feature. I’d like to allow only one active session per user. Is it recommended to call await authClient.revokeOtherSessions() right after login in Next.js, or is there a better way to handle this? What if I want to allow only the last 2 active sessions (i.e., revoke all older ones but keep the most recent 2)? Is there a built-in option for this, or should I manually do it?...

Bearer-token auth with social login?

Is it possible to implement bearer-token auth with socials? Just wondering if anyone has any experience with this...

OTP plugin usage

Hi, is there any reference code with showcase of usage email-otp plugin? Currently im strugling with checking otp code, cant get how to determine if otp typed by user is valid.

Setting up better auth for a swim saas

Hi, I am in the process of piecing together a competitive swimming saas that is similar to TeamUnify, SwimTopia, Hy-Tek's Team manager, etc that will allow coaches to manage their teams, swimmers to see their stats, parents to sign their kids up for swim meets etc. I want to primarily focus on the coaches right now but set things up so that parents and swimmers can be added in the future. This will basically be a multi-tenant app where the URL will look something like /team/[teamId]/*. Coaches, swimmers, and parents can technically belong to multiple teams at once. For example, lets say a coach is the head coach for the High School swim team and head coach for the Club team in town. Along with that, a swimmer could be associated to those two swim teams along with their parents. I know there's the organization plugin, but I wasn't sure if the organization would be the name of the SaaS or if it would be the same of the swim team. The reason I was unsure is it looks like organizations have teamId, and thought maybe that's what I should use for individual teams? However, I wasn't sure if a user could belong to multiple teamId within an organization or not. The ability to be associated with multiple teams at once is a huge need for this app to work....

Customize UI for Screens provided by Better Auth

I am using React Router v7 and Better Auth and I just encountered this screen that shows an error while I am trying to link an account that already belongs to another user. I wanted to know if there is a way to create a custom ui for screens like this?
No description

ERROR [Better Auth]: Failed to create user TypeError: value.map is not a function

I previously only had social sign in enabled, now I just enabled email/password but I get this error when trying to sign up. I am not exactly sure why this happens. I am using express + react Entire log ``` info: server running on 0.0.0.0:3030... {"timestamp":"2025-08-19T07:17:13.154Z"}...

What happens if the session freshness check fails ?

What happens if the session freshness check fails ? How do I prompt the user to refresh their session ?