Better Auth

BA

Better Auth

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

Join

bug-reports

help

Version 1.3.31 and v1.4.0-beta.13 type inference error

I tried upgrading to both 1.3.31 and v1.4.0-beta.13 from v1.4.0-beta.6 as i wanted to test a fix that was made to organization plugin in https://github.com/better-auth/better-auth/pull/5337
The inferred type of 'IamProvider' cannot be named without a reference to '.pnpm/better-call@1.0.24/node_modules/better-call'. This is likely not portable. A type annotation is necessary. (ts 2742)
The inferred type of 'IamProvider' cannot be named without a reference to '.pnpm/better-call@1.0.24/node_modules/better-call'. This is likely not portable. A type annotation is necessary. (ts 2742)
...

Getting error while using Postgresql only

This is how I have set up the database: ```typescript database: new Pool({ connectionString: process.env.DATABASE_URL,...

How to cancel Stripe subscription using API?

Hi, I want to allow users to cancel their subscriptions directly via the API because the default authClient.subscription.cancel just redirects users to the Stripe Billing Portal, which doesn’t suit my needs. I just want users to be able to click a button and cancel their subscription - nothing more. Has anyone achieved this properly? Currently, I’ve implemented cancellation through the API, but now I’m thinking about how to synchronize it properly with Better-Auth. I noticed that the database isn’t updated after I cancel a subscription, etc. My logic:...

The recommended way of using the admin's listUser with TanStack Start

what is the recommended way to use the admin plugin's listUser in TanStack Start? ```ts // OPTION 1 (authClient.admin.listUsers + useQuery) const fetchListUsers = async (): Promise<UserWithRole[]> => { const data = await authClient.admin.listUsers(...

Header

{ host: 'localhost:8080', connection: 'keep-alive', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1', accept: 'application/json',...

Express header

Why is my session in the backend giving null @Better Auth

Types are showing as 'any' on client after upgrading from v1.3.26

I had typescript working perfectly fine in V 1.3.26 where it was able to correctly infer everything. I am using a vite react project on the frontend. I have reduced it to the simplest example ```ts export const authClient = createAuthClient({});...
Solution:
Updated to 1.3.32 and this is no longer an issue. Related issue that confirms it: https://github.com/better-auth/better-auth/issues/5538...
No description

Getting session null in tanstack start beforeLoad

I am getting session null in following implementation ```import { Navbar } from "@/components/navbar"; import { createFileRoute } from "@tanstack/react-router"; import { authClient } from "@/lib/auth-client"; import { redirect } from "@tanstack/react-router"; ...
Solution:
wrote a createServerFn to get current users session in beforeLoad, my code looks like this @Nitish ```ts // src/routes/__root.tsx const getSession = createServerFn({ method: "GET" }).handler(() => { return authClient.getSession({...

How can I use Better Auth with a Node.js Express backend and a separate Next.js frontend?

I’m building an application where the backend is a standalone Node.js + Express server, and the frontend is a separate Next.js app. I’d like to integrate Better Auth for authentication and user management across both.
How can I properly configure Better Auth so that:
- The Express backend handles authentication logic and token validation securely.
- The Next.js frontend can interact with the backend for login, signup, and session management. ...

Organization Cache Not Invalidated on Logout

Hi everyone, I am experiencing a caching issue with useListOrganizations() and useActiveOrganization(). When logging out and logging back in with a different user, the queries from useListOrganizations() and useActiveOrganization() return cached data from the previous user's session instead of fetching fresh data for the newly authenticated user. Is there any known fix for this?...

typing error with custom field

I’m getting a TypeScript typing issue where additionalFields become never or null | undefined in the signUpEmail body. This happens even with the example from the docs (lang field). config (in a separate package in a monorepo) : ```ts...
No description

Failed to create verification

I am trying authentication for the first time with BetterAuth and am running into the following error:
Failed to create verification: null value in column "id" of relation "verification" violates not-null constraint
Failed to create verification: null value in column "id" of relation "verification" violates not-null constraint
Does this ring any bells for something obvious I have done wrong?...

Does better-auth support custom fields in 'create' events like``authClient.organization.createTeam``

It's in the name really. Currently, you can create a team like this: ```ts const { data, error } = await authClient.organization.createTeam({ organizationId: team.organizationId,...

Getting '# SERVER_ERROR: ' [TypeError: Invalid URL: '/'] on Github OAuth login

Hey there, So I am building a mobile app using Expo and a web app using next using the same Convex project as the backend and Better Auth for auth. The mobile app is working just fine, but when i try to set up auth in the next app I keep running into errors. When I try to sign in with github i get an 500 internal server error, and in the convex logs i get: [CONVEX H(POST /api/auth/sign-in/social)] [ERROR] '# SERVER_ERROR: ' [TypeError: Invalid URL: '/']...

Database/environment injection when creating Better Auth instance on the server

New user here 🙂 It's pretty common to use dependency injection to instantiate database connection. But according to the docs we must use better-auth like this:
Make sure to export the auth instance with the variable name auth or as a default export.
This means we can't create the auth instance inside a function, it musy be at top-level. But we need to pass the database while creating the Better Auth instance, and we use a function to create it for dependency injection purposes. Anything we can do here? We were surprised that we couldn't find anything about this on Github....

[Urgent] I keep getting 401s for valid API-Keys

Hey everyone. I deployed the latest version of my app but keep getting 401s (in prod) and I can't seem to find the issue. In my testbox I'm logging this: ```...

Reset password - Auth login.

Hello, is it possible to have the user login automatically when they change their password from the forgot password button. Currently I just have a redirect to the login page. Would be nice if it could be automated....

Sending additional custom fields on sign-up.

Is there a way to send some custom data in the authClient.signUp.email function. This additional data will not necessarily be stored in my database but is needed for some logic in the "user create after" database hook.