Better Auth

BA

Better Auth

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

Join

bug-reports

help

E2E Tests with BetterAuth

Hello, I am making E2E tests and am having difficulties authenticating my API requests. I am making requests with fetch (should I use something else?) and naively thought it would be enough to use use credentials: 'include' to authenticate with cookies. I suspect this doesn't work because BetterAuth sets cookie samsite attribute to lax, thus ignoring credentials: 'include'. So in short my question is, how am I supposed to do E2E testing with BetterAuth?...
Solution:
I solved it by changing from using fetch to using supertest, which allows automatically setting the cookie via the Supertest Agent.

How to close passkeys prompt

Stack: Elysia & Tanstack Router I'm using passkeys conditional UI (propt opens automatically on page load). When user logins with any method that does not require page reload (e.g. email OTP) paskeys prompt (1password in my case) remains open. How to close it?...

Disable email fields (email login) i am only wanting to allow access-key auth

Disable email fields (email login) i am only wanting to allow access-key auth any idea what the best approach is?

Error codes are not strings?

I was trying to compare the error code returned from the authClient, but when I print the value of the enum it just prints Proxy so the switch fails. See screenshots
No description

What's the difference between additionalFields and customSession?

Hi, it's a bit unclear to me the difference between additionalFields and customSession plugin. I am trying to migrate an app using Prisma, and I have a User schema that have many other fields. My understanding is that I should add those fields under user.additionalFields in auth.ts. However, most of those fields are many to many relationships with other tables, so I cannot use the proper type in additionalFields. ...

Storing Session Data

I have drivers who essentially run deliveries. They will sign into my website and then start a route. How can I store current route id that they are doing as part of their session? The cookies page doesn't really specify very well. https://www.better-auth.com/docs/concepts/cookies...

Is it possible to add multiple authentication systems?

In my app, I have a the better auth user authentication system, but I want to use organizations as tenants. Each organization should have its own authentication system, allowing ‘Participants’ within an organization to log in separately. Is this possible? One way I was thinking was to have two instances of better auth, but maybe that becomes too much?...

getSessionCookie() always null | Next.js 15.2

In my middleware I am using getSessionCookie() to check if a user has a session cookie. My middleware looks like this (shortend): ```ts ......
Solution:
The issue happens cause the getSessionCookie helper is expecting __secure prefixed cookie but the server is still setting non secure cookie cause it's running on http. You can pass useSecureCookie:false in get session cookie config. Or update to 1.2.5-beta.3 which sohuld fix the issue.

Any way to use split Access Tokens and Refresh Tokens

Hey so I just started using Better-Auth coming from my own Auth System. I'm trying to use short lived access tokens with refresh tokens but I'm not seeing anything about how to do this in Better-Auth. All I'm seeing is the Bearer plugin which seems to be the closest but it seems to combine the access and refresh token into 1 token essentially. I'd like to be able to use the Bearer plugin with an access token that stores the current user's state (email, username, login options, etc etc) that expires after say an hour. At the same time as generating the access token I would generate another token that only stores the user id and expires after 14-30 days, this token is also passed to the client, but unlike the access token, is stored in the session. The access token is used in the authorization header for authentication, but the refresh token is used to get a new token pair by calling to the token endpoint (for me I did /auth/refresh in my system). Any ideas? My thinking was to just make my own plugin, but I just wanted to ensure there wasn't something I was missing before doing that. Thanks!...
Solution:
Better Auth doesn't issue 2 tokens. Only one token is issued by default. But we have a concept of cookie cache that kind of serves the same purpose. https://www.better-auth.com/docs/concepts/session-management#session-caching...

🛑 Next.js 15 – “cookies inside use cache” Error in Layout Component

Hey everyone, I’m running into an issue in my Next.js 15 app when trying to fetch session data inside my DashboardLayout component. I need to pass request headers to my getSession function, but I keep getting the following error about accessing dynamic data sources inside a cache scope. I’ve tried extracting the headers outside the function and passing them as arguments, but the issue persists. Has anyone encountered this before? Any ideas on how to properly handle this while keeping caching?...

Multiple Organization : Unable to ugprade

When we have multiple organization, and I want with the same owner account to upgrade one account and then the other with the same plan, I get this error.
No description

getSession causing error: "Cannot read properties of undefined (reading 'validate')"

Hey, I'm trying to build my auth on my hono backend but I'm getting an error in my middleware when getSession() is called. I was able to debug it and found out that when calling the getSession() function some kind of TypeError happens in the context (see screenshot). Just for clarification: I needed to initialize my better-auth instance via a function so I could pass the Cloudflare workers env bindings into my better-auth instance, as with CF workers it's not possible to access the process envs....
No description

user.findFirst and session.findFirst being run too many times

Is the queries user.findFirst and session.findFirst being run to many times normal?
No description

[RangeError: Too many properties to enumerate]

When i try to get session, via the /api/auth/get-session or via the getSessionCookie helper, i always got a 500 error with "[RangeError: Too many properties to enumerate]", without any others details. If you have some ideas to solve it, it would be a pleasure thx...

How to seed users?

I want to seed some users, and I have a json with user names, emails, passwords. this is going to be a backend script that I run manually. I wonder whats the best way, currently all failing. tired await authClient.admin.createUser, and that is failing, I guess because it only works if the users who runs this is an admin user. and at this stage i'm running this as a script, with no user. also tried await auth.api.createUser , and that also failed with status 'unauthorized'. any idea?...

Can i setup two separate auth config in single project

is it possble to have separate auth config for an single projects separate user base...

Add current Stripe plan to user object

Hello, thanks for the awesome Stripe plugin. I was wondering if it is possible to include the Stripe plan which the user is subscribed to on the user object. This would look like this: User = { id: string; [...]...

Vercel Deploy Problems - Cookies not detected?

I just deployed my app to vercel and m ycookies are no longer detected? I sign in e.g. with a. magic link, i see my cookies in the application but i dont get redirected or whatever When i run it locally i do get redirected, only difference is one is deployed on vercel and the other isnt...

Broken auto sign in?

Hey! I have auto sign in enabled in emailAndPassword. But after signing in, nothing gets auto signed in. Is there another thing that has to be enabled or am I missing something? I am signing up in sever, but nothing reflects on client side, not even after refresh....
No description

Azure B2C vs B2B

Is Azure B2C flow supported somehow? I want to pass my custom policies, but it seems https://www.better-auth.com/docs/authentication/microsoft has no parameter for that. The URL opened by BetterAuth is https://login.microsoftonline.com..., but B2C opens https://smthg.b2clogin.com/smthg.onmicrosoft.com/mypolicy/......