Better Auth

BA

Better Auth

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

Join

bug-reports

help

session returning null

Hi guys, Question. I have implemented better-auth into my express.js server and I got it working with email and password (sign-up/in) but when it comes to getting a session I get a status code of 200 but a null in return. Basically just followed the docs on installation and under integration of Express. But is there some headers object that I need to catch to get the session or have I missed a step?...
No description

Using Drizzle, do I still need to fill in all the values on `session.additionalFields`?

Do I have to duplicate the config across from drizzle to better-auth, or will drizzle handle it? Specifically: - defaultValue? - fieldName? If I've set drizzle to convert to camel_case internally - references? If I've told drizzle the refs already...

Sharing resources between orgs

In my usecase , one organization (system) Crete global todo tasks and they should appear in all other organizations todo list along with their own todos Looking for help how to implement with orgs and permissions...

Error /sign-in/social 404 - Apple provider

Hello, I am using Hono as my backend server and SwiftUI for iOS client. I'm having some trouble with sign in with apple, I have email/OTP and anonymous auth setup and they work. When i use the handler like this ```...

Email Verification Complete hook?

Hello, I am making a Nuxt 4 Application with Better-Auth and wanted to ask how can I create a Hook that will fire on Email Verification Successfully. I need it at a Point where the session is already established (or how would it be done) to insert Data to a custom table for my Application...
Solution:
okey so I found this to be helpful: ```ts emailVerification: { sendVerificationEmail: async ({ user, url, token }, request) => { // send mail logic...

Bearer token with social login

Hi, I am having trouble setting up bearer tokens with social login. The server sends the token back in the header set-auth-token but the client is not receiving it. auth.ts: export const auth = betterAuth({ database: prismaAdapter(db, { provider: "postgresql" }),...

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. ...
Solution:
Here's a summary of the issue i faced: * Vercel's default .vercel.app subdomains don't allow cross-origin cookie sharing. * This means subdomains like floxify-fe.vercel.app and floxify-be.vercel.app can't share cookies. * Cookie sharing works fine when using your own custom domain (e.g., floxify-fe.floxify.ai and floxify-be.floxify.ai)....

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....