Better Auth

BA

Better Auth

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

Join

bug-reports

help

Typing Role

I am using an enum from Prisma but I cant pass that enum as a type for additional fields ```ts...
No description

Type error defining stripe plugin when project type is module.

I have both stripe plugin and better auth on the same version 1.2.5. When i switch my project type to module then I get the following type error. I cannot solve it.

Problem When Updating the User in the Session

I set up Theo’s uploadthing to handle my image uploads. On the uploadthing server, I update the user’s image in the database like in the code below. I did not use authClient.updateUser to update the user's image in the database. Now, every time I have a successful update, I check my database and see that the user’s image is updated correctly. My only problem is that the content of the user in the session authClient.userSession does not update—it seems there is about a minute delay before...
Solution:
This is not your fault! Essentially, useSession will only update whenever a relevant endpoint was called from the client which would have something to do with modifying the user session. Since you're updating the user's image from your server, the BetterAuthClient doesn't have a way of knowing that - thus it doesn't update. ...
No description

Refresh provider access token using genericOAuth plugin

I am looking for a way to refresh the access token from my custom oauth provider. I can see it and the refresh token along with the expiration stored in the account table in the DB, but I'm not sure how to update them. Here is my config setup: ...

getSession null

why useSession works but using getSession i get null

Stripe Plugin

I was wondering how to handle "proration" ? I don't know if this the good word for this. Example : I just bought the 5$ basic subscription and want immediately buy the pro plan at 10$, I won't pay 5 + 10 Example : I'm in the basic plan at 5$, I want in the middle of the month upgrade to the pro plan at 10$...

Account Linking

Hi there, I'm using better-auth for authentication in my app, and I want to support two providers: Google OAuth...

Cloudflare assets_navigation_prefers_asset_serving breaking oauth redirect

Hello Everyone. Cloudflare recently changed how some of the navigation things work for SPAs and now a default better-auth oauth setup dosent work anymore. The issue here is that after i click on an account on google, i get redirected to http://localhost:5173/api/auth/callback/google?state=.. but this is now seen as a "client side navigation" and just serves my html file instead of going to the server. I dont have any non default setting on my client or server ...
No description

Multiple Session Types / Customize Options for Individual Sessions

Is it possible to arbitrarily define values for different options (like expiresAt, updateAge, secret, rateLimit) for how an individual session is generated based on something like a request header? For context, I am working on migrating from a custom JWT auth system to Better Auth for a service that has 3 main parts: - Next.js Website - Express API + MongoDB...

AccountId

How do I get the account ID in the case of a social connection with Discord for example? Do I have to make a Prisma request? Because I can't find it in the Auth API Get Session

getSession always returns null

i have the following auth-middleware that i can confirm is receiving a proper header. I manually search for the session and was able to get a matching record from the db. I did this both inside a db client and within the middleware using the db adapter to retrieve the record. I see that have bee others with similiar issues. I was wondering if this is a known issue (i don't see a open issue on github) or if there is a work around. I'm setting up the server so i don't have a client setup. I'm using a rest client to make calls into the server. I'm on the latest version of better-auth auth-middleware ```typescript import { Session, User } from "better-auth/types";...

Implementing User Roles

Hello, I am trying to implement roles of USER, MODERATOR, or ADMIN I find the admin and organization plugins a bit intimidating but more importantly I am not sure if they are the exact use case for my roles ...

get env bindings from better auth email function context.

So inside of sendResetPassword I need to get my hono context to send emails, since my resend api key is in cloudflare workers and I am using JStack, how can I achieve this?

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