Better Auth

BA

Better Auth

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

Join

bug-reports

help

Email OTP SignUp

Hello, we're working on implementing the Email OTP flow and have a couple questions: - Is there a way to create a user while disableSignUp is enabled? I enabled it because we want to manually sign up new users only via an admin page, and want to block login attempts for unregistered emails. However there doesn't seem to be any other way to sing up a user with this plugin. - The only workaround I have found is to also enable the emailAndPassword flow, and then create users that way with a very random password that will never get used. And now that the user exists, the OTP flow seems to work as expected. Could this cause any issues or does it seem like a safe approach?...
Solution:
if you have an admin plugin you still can create an new user as well if you want - https://www.better-auth.com/docs/plugins/admin#create-user

Polar

Hi, im creating a licensing website and i want to make if user buy the product it will insert it ( or run API ) in the dtb. Is it possible with polar to automatically insert or i do need to create a redeem key that will redeem - add the license?

Email & Password verification with refresh token

Hi I was going through the docs looking for examples of email password sign in (using rest api with a backend) and JWT refresh-token handling. Basically at work I have a backend with a login and refresh endpoints and those return a jwt/refresh token. Has anyone implemented this or have I maybe missed it in the docs?...

Server side validation

Docs are showing examples of implementation of betterAuth using auth-client, which is great, simple, with callbacks to handle errors, etc. BUT it allows only for client side validation which is NOT SECURE as you can bypass it easily and harm server, db, etc. How do I add server side validation of all the fields for signUp/SignIn? I know I can use auth.api.(whatever) but then I need to handle all the errors and other stuff by myself. Am I missing something? Does betterAuth library makes some serv...
Solution:
you can use try catch if u want - ```ts import { APIError } from "better-auth/api"; try {...

How to refresh cookie cache

Hey! I have a nextjs application and im mostly using client components to fetch user session. I would like to use the BA cookie cache functionality to avoid querying the db for each session. I can see the cookie cache is set whenever a user logs in. ...

Polar error after upgrading to zod 4 beta

There is an error when i updated my zod version to latest zod@4-beta ```ts β¨― TypeError: TURBOPACKimportedmodule$5b$project$5d2f$node_modules$2f40$polar$2d$sh$2f$sdk$2f$dist$2f$esm$2f$models$2f$components$2f$customfieldcheckbox$2e$js$5b$app$2d$route$5d$$28$ecmascript$29$__.CustomFieldCheckbox$inboundSchema.and is not a function...

Updating better-auth schema after re-defining Prisma Schema

Hi Guys. I have a NextJs15 application that uses Prisma as an ORM and used the " bunx @better-auth/cli generate" to generate my Prisma schema and all worked perfectly. I them proceded by creating all my necesarry methods for login on the server side and all this worked flawlessly as well. The problem I have is now that I updated my Prisma Schema and ran the "bunx prisma migrate dev --name add_user_role_fields " migration it seems that even if I then try and update the Better-Auth Schema it does not want to work. I run this for the update: "bunx @better-auth/cli@latest generate --output lib/generated/prisma/schema.prisma"...
No description

Retrive organizations members with bearer token

Hello ! I use the bearer plugin to authenticate requests to a websocket server that cannot support the better-auth default format. I take as parameters the name of an organization (I've enabled the plugin) and the bearer token....
Solution:
My bad, my vscode autocompletion just sucks, i just need to pass headers with the same way to authorize correctly

How do teams work in user management?

In the schema section of the organizations plugin, I can see that there is a member table that connects users to orgs. However, there doesn't seem to be any tables that connect users to teams. How is that supposed to work conceptually?
Solution:
The relationship between users and teams is actually managed through the member table, which serves as a junction table between users, org , and team.

ctx.error type

```js const handleSubmit = async (values: UserLoginValues) => { await authClient.signIn.email(values, { onError: (ctx) => { console.log(ctx.error);...
No description

Getting SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')

When I build my express js app using better auth, this is what I get whenever an auth function/endpoint is called. How can I fix this? ...

Session cookie not working in production deployment

Hello everyone, Unfortunately, my authentication only works on localhost and not in production or the deployed development environment. We have multiple frontends. Central authentication runs via an Express API (api-ts.playin.gg). The test frontend for authentication is auth.playin.gg....
No description

useSession is not is not callable ?

need help with the clients hooks every client hook gives me a typescript error like this `` This expression is not callable. No constituent of type 'Atom<{ data: { session: { userAgent: string | null | undefined; id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; }; user: { ...; }; } | null; error: BetterFetchError | null; isPending: boolean; }>' is callable.ts(2349)...
Solution:
My guess is your auth client is importing createAuthClient from better-auth/client rather than better-auth/react

Error on generate schema with prisma

```bash npx @better-auth/cli@latest generate 2025-04-10T01:52:48.957Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. at new PrismaClient (/Users/filliperibeiro/Desktop/www/pessoal/structura/node_modules/.prisma/client/default.js:43:11) at /Users/filliperibeiro/Desktop/www/pessoal/structura/lib/auth.ts:5:16...
No description

How to make two unique fields in a schema

So I'm trying to make a plugin with many to many relationship. I want it to have teamId and branchId columns. the combination of teamId & branchId must be unqiue, how can I achieve that? ```ts schema: { teamOnBranch: { fields: {...
No description

How do I use the auth.api.deleteUser endpoint from a server action?

I am trying to figure out how to invoke different auth.api endpoints from my server code in NextJS. I cannot seem to figure out what the implementation should be.

account_not_linked: I have react and express setup and using better auth

How to get this error to the frontend, right now it renders the better-auth error page

cloudflare + better-auth and turso

How to setup this in cloudflare any idea
No description

User avatars/profile pics for Microsoft Entra social sign in

Hello, I am trying to implement social sign in with Microsoft Entra. In the Entra dashboard my App Registration has selected User.Read and User.ReadBasic.All (the latter gives "Allows the app to read a basic set of profile properties of other users in your organization on your behalf. Includes display name, first and last name, email address and photo.") My better auth config lists the User.ReadBasic.All scope:...
Solution:
So I've partially solved it. I've confirmed scope: ["User.ReadBasic.All"] is correct, but the image doesn't provide the placeholder you see in microsoft apps if an avatar isn't explicitly set.

Determine if new user without callbacks in expo

When using authClient.signin.social in an expo app the deep link callbacks don't currently work, sounds like it should be fixed in an upcoming version. In the meantime I'm using the workaround that is in the example expo project to force a redirect after authenticating: ``` useEffect(() => { if (isAuthenticated) {...