Better Auth

BA

Better Auth

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

Join

bug-reports

help

Cookies are not being passed from the front end to the back end in production within the monorepo.

hellow guys, I'm facing an issue on production where cookies aren't being passed from my Next.js frontend (platform) to my Next.js backend (API) within a Turborepo monorepo setup on Vercel. but working fine locally. ...

Organization update error

I have been trying to update organization but it giving Invalid body parameters , I added additional fields to it as well. It's in the link below the code https://pastebin.com/Xr3EWhcV @ping @FalconiZzare...

Admin Plugin Docs Question

Hi! I'm making an app right now and came across this in the docs. Shouldn't the impersonatedBy property have that little Foreign Key tag? The property references an ID from the users table after all, doesn't it? Is it a compatibility issue for some databases or adapters - do some not have the option for optional foreign keys?
No description

Custom email encryption / customize data saved in sessions

I just switched from auth.js (formerly next auth) to better auth, and I don't quite understand how to set up custom sessions. With auth.js, you could decide what was stored in the session. Since I only store all emails as hashes and encrypted versions in the database, I don't want them to be visible in the session as plain text. So, how can I adapt the session accordingly? I also need additional fields (role, for example) in my session that are also stored in my database.

Redirect to custom error page

throw new APIError("FORBIDDEN", {
code: "FORBIDDEN",
message: "Access denied. This application is currently in maintenance mode.",
});
throw new APIError("FORBIDDEN", {
code: "FORBIDDEN",
message: "Access denied. This application is currently in maintenance mode.",
});
...
Solution:
You could add a mapProfileToUser in the discord provider config, then check the needed info to throw an APIError and redirect to a custom error page:

SvelteKit session not reacting after auth.api.signInEmail

Hi there, After a form post, then auth.api.signInEmail, I use svelte redirect to go to the home page, but $session doesn't react. I have to manually reload the page for the session to reflect...

what is the header for the token ?

i'm trying to use postman to test my app but i can't get the auth working. what is the header for the token ?...

Resend Email Verification not working.

When user signup on the system using email and password then after successful sign up sendVerificationEmail is send which is good. But when the user sign in without verifying the email then on UI side it send the email not verified which is also good. However, as per the documentation it says that ``` If you enable require email verification, users must verify their email before they can log in. And every time a user tries to sign in, sendVerificationEmail is called....
No description

Organization update error

I have been trying to update organization but it giving Invalid body parameters , I added additional fields to it as well. It's in the link below the code https://pastebin.com/Xr3EWhcV @Ping...

Build Process for Forks

Hi folks, I forked and send a PR to allow database drivers that override timezonez handling. In my case, I use all strings on the backend with postgres, which only works with a small modification: https://github.com/better-auth/better-auth/pull/4298 To write tests and test this in prod, I need to wire up this fork, but I'm hitting a snag - simply building doesn't seam to produce the same output as the npm package? With my fork I'm hitting errors on vercel:...

Expo + Convex + Better Auth

Hi everyone! Do you know of a working example implementing Expo + Convex + Better Auth? Is this possible at all right now? Thank you!...

set default value on database level when extending core schema

I have been using better auth with drizzle-orm , the dx is pretty great but , the ability to add default values in db is very crutial , as of now when i extend my core schema and give my default value it just adds it in the js layer not in the db layer , is there any workaround for this?

Mapping IDs for Discord OAuth

Hi, I am trying to map the user id to the profile id when returned from discord sign in. I want the discord ID to be the primary key and id for the user table. I have tried mapProfileToUser and it still generates a UUID. Any help would be appreciated. Here is my Auth.ts.

Express integration: /api/auth/session and /sign‑in/email return 404, but auth.api.getSession works

We’re using Better Auth 1.3.7 with Express (Node 20) behind Cloudflare/Railway. Programmatic calls resolve the session correctly (auth.api.getSession({ headers }) → hasUser=true), but the HTTP routes return 404: GET /api/auth/session and POST /api/auth/sign‑in/email. We mount with app.use('/api/auth', toNodeHandler(auth)), trust proxy is set, CORS and body parsers are mounted before the handler, and we’ve verified prefix stripping via logs (handler receives url=/session and url=/sign‑in/email). Admin APIs using the same cookies return 200. As a temporary unblock we added a small server endpoint for GET /api/auth/session that proxies auth.api.getSession so our SPA guard can proceed. Is there any known configuration nuance or route registration issue in 1.3.7 that could make the HTTP endpoints 404 while the programmatic API succeeds? Any guidance or diagnostics to surface handler-level 404 reasons would be appreciated....

Large cookie size breaking login

This seems to be the same question that's already been asked, but it was a few months ago. I want to check if there's been an update since: https://discord.com/channels/1288403910284935179/1357381653067989214/1357381653067989214 I don't see why it's important to store the image in the cookie and then go over the browser limits. What we were able to do on NextAuth is just remove the image from the cookie. We store the image in the database, but it doesn't need to be stored on the cookie level. I'm curious, is there some way to do this in BetterAuth? This isn't a huge headache because this is quite a bad bug....

Renamed email field via auth config results in auth error

Using better-auth@1.3.8-beta.3 with prisma adapter I've renamed several columns via the auth config (to use snake case column names), and also changed the database column names (via prisma migration). But upon logging in there's a query error thrown which is attempting to use the custom field name email_address instead of the prisma model name email. auth.ts...

email sign up fails with error: "FAILED_TO_CREATE_USER"

Hi community, I have this issue where I constantly get the error FAILED_TO_CREATE_USER with an error code 422, when i try to sign up a user via email. I have added a screenshot of the network error logs. I couldn't figure out what I am doing wrong. Did anyone experience something similar and can help? ...
No description

Trying to connect kysely-neon with Better Auth but failed.

I don't know what causes this, but apparently coming from the configuration. I already created my src/lib/auth.ts file inside my SvelteKit project. And this is my code: ```typescript import { betterAuth } from "better-auth";...

Have anyone manage to get OIDC working with genericOauth

i keep getting this error ``` 2025-08-28T15:24:05.992Z ERROR [Better Auth]: State Mismatch. Verification not found { state: "SAWTsHvhONj2IiZKdnrNB98AXUhs1X3L",...

Email Verification Email is not Sent

I've been trying to add emailVerification to my app for some time, but didn't get it working. My function works well, doesn't have issues when trying it externally from better auth. But when I am trying to make it send the email, it does not work. ( Added prints and it looks like the function isn't called ) ```ts emailAndPassword: { enabled: true,...
Solution:
It looks like the verification email isn’t being sent because the configuration is misplaced. According to Better Auth’s documentation, options like sendOnSignUp and sendVerificationEmail should be defined under the emailVerification configuration rather than inside emailAndPassword. In your snippet, they’re currently under emailAndPassword, so the framework isn’t triggering the verification email on signUp [1], [4]. To fix this, move these options to the emailVerification object in your auth configuration. This should ensure that the email verification process is correctly triggered on signUp. Sources:...
Next