Better Auth

BA

Better Auth

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

Join

bug-reports

help

Cleanup of expired organization invites

Hi, I've noticed that there are a few places where better-auth generates records e.g. organization invites where they expire. How does better-auth go about cleaning up expired records when they're created?

Get Members of an Organization

hey, could someone explain what this function does? https://www.better-auth.com/docs/plugins/organization#get-active-member I want to list all the members in the organization.. how do I do that?...

Microsoft login not working

Might be being mega dumb here but I have followed the docs and trying to have just a Microsoft login. Clicking my "Login with Microsoft" button just loops me from /login back to /login? and the only thing that happens in my DB is a record created in the Verification table. Why wouldnt this be signing me in or creating me as a user?...

membershipLimit for Organizations

Hi, I can see that it's possible to set a limit for team members but is this possible for Organizations?
Solution:
You might have it the wrong way around, we have a membershipLimit, but no team member limit

Session Not Persisting in Production (Docker) After Social Login

Hi, The authentication flow using better-auth and social login works perfectly on localhost. When I log in with a social account, the session is correctly created in the database, and the user appears as logged in on the site. However, when I run the same setup in production inside Docker, the session is still created in the database, but the user does not appear as logged in on the website. It's like the session is not being recognized properly in production. ...

Error [TypeError]: Cannot read properties of undefined (reading 'encrypted')

I'm trying to set up Better Auth on the Next.js edge runtime using toNodeHandler (required for the pages router), but I'm getting the above error. Has anyone managed to get it working on the edge runtime with the pages router?...
No description

How to setup neon auth with better-auth

Hi everyone, could you please assist me in setting up Neon authentication with BetterAuth using the JWKS API in Next.js?...
No description

Reusing Captcha token on signin/signup

Basically, I mount the Turnstile captcha once and if the user needs to sign in again (due to e.g. incorrect password), the captcha verification fails (which makes sense since the captcha token already got used) Is there a way to perhaps issue a “captcha session” token which lasts for an hour or so, allowing the user to not have to do the captcha again?...

Infer type before initializing betterAuth

I'm trying to create a class that to migrate our system to betterAuth, while keeping the current system in place for the time being. I know what plugins are going to be enabled, but things like database password, appName and others will be passed in via configuration options How do I correctly define the type for the authInstance so that I have access to all the plugins?...
Solution:
I think I got it. Here's the diff of the changes I did ```diff --- oldAuthClass.ts 2025-05-07 18:11:43 +++ authClass.ts 2025-05-07 18:12:53 @@ -1,5 +1,5 @@...

Existing Userbase from Clerk -> Better Auth

Are there any articles or help regarding moving from clerk with 20k+ Users to better auth? Including all their passwords etc. What are in general best practises?...

how to pass extra data to sign in functions

I have custom roles in user table that i want to specify so that the created user is created with the correct role depending on how they sign in. ```ts await authClient.signIn.magicLink({ email: values.email,...

Admin-plugin. Is there an elegant way to create first app admin?

Possibly dumb question but for the admin plugin is there an elegant way to create the first admin in your app. I know you can 1. manually go check their id then add it to the better auth adminUserIds setting or 2. sign them up on db bootup and write a query in your db of choice to change their role, but 1. requires you to patch the code right after you just deployed it and 2. brakes the nice db encapsulation better auth has going on. Neither are bad options, but it feels off. Like I'm potential...
Solution:
update: ``` const newUser = await auth.api.createUser({ body: {...

Multiple apps sharing the same database using Better Auth

im using nextjs in a monorepo like this apps: example.com (account portal like billing etc) product.example.com (spereate nextjs app)...

UUID Confusion with database orm

Hi I just recently switched from Prisma-orm to Drizzle-orm in the project that I am working on. Having a bit of issue where my user table doesn't seem to understand the uuid coming from my sign-up form. Curious to see if anyone knew exactly what I have done wrong?
Solution:
Yes this is completely fine. If you want the old way where your DB handles ID generation, you can disable Better-Auth's ID generation by passing advanced.database.generateId as false in your auth config.

Full access from a microservice

I have a requirement for which I need to use ABAC. I would like to use a different service to handle permissions. I also want to be able to use the admin plugin. Is there any way i can get a full permission api key so my service can contact better auth as admin?

How to check organization permissions on server without making API call?

I want to just check permissions in a similar way the client organization offers - is there a way to get the "roles" from access control?

Setting additionalFields w/ secondary storage

I'm creating a default API key when someone signs up, like so: ```ts import KeyvSqlite from "@keyv/sqlite"; import Keyv from "keyv"; import { betterAuth } from "better-auth";...

ERROR [Better Auth]: Error Error: NOT_FOUND

``` api-1 | 2025-05-05T18:47:57.241Z INFO [Better Auth]: Auth initialized api-1 | [18:47:57.242] INFO (38): Starting server on port 80 api-1 | auth handler http://auth.localhost/auth/get-session <- this is the requset I get api-1 | 2025-05-05T18:48:09.551Z ERROR [Better Auth]: Error Error: NOT_FOUND...

Get enabled authentication methods

Is there any way to get an array of the available authentication methods from the auth client? That way I could create my login component to automatically show whicever ones are setup.

How to Get User after SignUp with Hooks when requireEmailVerification is true

For some reasons, since email verification is required after sign up, I couldnt get user context in the hook. With the After hook, I populated some modeled data to the database after sign up. But since email verification is required to get a session Im kind of stuck. All I need is the user.id after the signup. And this Id is sent as a response to the user after sign up. from the Middlewarecontext i am able to get a request body, Is it possible to get a response? Or is there a way to go around this to get a UserID after they signUp from middleware? Or Do I have to do something else?...