Better Auth

BA

Better Auth

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

Join

bug-reports

help

context.get is not a function better-auth (react-router 7)

React Router 7 Framework mode Better Auth with Prisma and Zod (conform) how to fix this context.get? on the loader...
No description

rate limiting server actions

Hi, i am using server actions for sign up, sign in, forgot password & reset password. But I don't see any rate limiting (even though I enabled rateLimit). Is this because calling auth.api from server actions is not rate limited? What if I want to protect my auth actions from misuse? I tried both using radis as secondary storage and as custom storage for rate limiting. Also can anyone please tell me why I can't see the prefix being used (passed to secondaryStorage)? ...

Seeing several type errors / breaking changes after updating 1.2.5 -> 1.2.8

Running into some issues after upgrading better-auth: - fetchOptions is no longer accepted in auth.api calls - query now appears to be required for auth.api...

Stripe Trials are not working properly

Im trying to implement trials using stripe plugin and everything works fine except that trial_start, trial_end and cancel_at_period_end are set to NULL in the database. How can i fix it? P.S. I'm using BA v1.2.8 with Stripe v.18.1.1 (i tried switching to 17.7.0, same issue there)...

Sub domain auth

I am trying to make the session available by requesting from sub domains like *.domain.com (I need to include all sub domains) Has anybody managed to achieve this kind of functionnality? If so, how you did it ?...

Confused about Better Auth + Backend Middleware + Auth

Hey, folks Im using Better Auth for authentication on my server (using Effect-TS). There is a middleware (not in better-auth config), that needs to check 2 scenarios basically: 1. IF there is a session cookie, which needs to be validated (not idea how), THEN user is authenticated....

Setting baseUrl doesn't work when BETTER_AUTH_URL does

In my project, I have to specify the app url twice because I have the app url set as PUBLIC_URL and then I need to set BETTER_AUTH_URL as well to make better-auth work. I have tried setting it with baseUrl in the auth config, but the api always just gives a 404, even though it's set to the same url as the env variable.

[Admin Plugin] Session not updated when user is updated

I'm using secondary storage, and when I make any type of user update through admin plugin, session is not updated. I was trying to use authClient.admin.setRole(), but noticed session isn't updated at all after this or any other update. Is that a bug?

How to enforce user's to set certain user properties?

Hi, I've been thinking on this for a while now. How do I force user's after the first login (or possibly on admin reset) to set certain attributes like a username? Right now I use a middleware, but I read in the docs that this might not be the best idea (and also for some reason the middleware stopped working after my last prod update)....

Better Auth (auth.api.getSession) causes problem in edge runtime

Hey everyone, I am new to using Better Auth. I am using a middleware to call auth.api.getSession() to check if the user is authenticated: • It grabs the current request headers (cookies, tokens, etc.). • Passes them to auth library (likely better-auth or next-auth) to fetch the current session. • If no session exists, it redirects the user to /sign-in....
No description

Infer type is empty in hono

In the auth.ts file , while following the hono better-auth docs. It states to infer the user and session type use auth.$infer. But in my case that is an empty object. I am binding that to Hono app by const app = new Hono<{Binding: AuthType}> which according to docs should set the type for users and session. this is the type that i get back when using auth.api.getSession()...
Solution:
hello also check your config (like empty plugins array etc), had this kind of errors before too...

Inferred type of betterAuth client exceed compiler serialization

Hi, Im getting this typescript error in my project. Any suggestion on how to solve it? `The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.``...

create organization on signup

What is the best way to handle creating organization when user signs up? I implemented email sign up, I am not sure where to put creating organization logic....

Generate OneTime Token not typed on client side

well i have implemented according to these docs: https://www.better-auth.com/docs/plugins/one-time-token but its showing this type error on client instance....
No description

mapProfileToUser throwing The inferred type of 'auth' cannot be named without a reference to '../../

I am using a monorepo using turborepo and when i use mapProfileToUser in the oAuth provider options i get this error:
The inferred type of 'auth' cannot be named without a reference to '../../../../node_modules/better-auth/dist/shared/better-auth.Bzjh9zg_'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'auth' cannot be named without a reference to '../../../../node_modules/better-auth/dist/shared/better-auth.Bzjh9zg_'. This is likely not portable. A type annotation is necessary.ts(2742)
...

signout doesn’t show logged out right away; I have to reload the page to see it.

When I implement signout and click it, it doesn't immediately show the logged-out display; instead, I have to reload the page to see the change. repo - https://github.com/ritiksharmarj/analytics.ritiksharma.me/blob/main/components/app-header.tsx#L77 better auth dir - https://github.com/ritiksharmarj/analytics.ritiksharma.me/tree/main/lib/auth ...
Solution:
if you're fetching the session on the server, you'd have to revlidate to be able to see the updated session (the logged out one).

ERROR api/auth/sign-in-social

Hi everyone, I am beginner with better-auth. I do setup a Auth with my project but i got error 404 not found. Is there some tip for fix this issue?
No description

AdditionalFields not working as expected, Drizzle

So I'm at my wit's ends, having scoured the web for a similar issue and having tried every config combination imaginable. It's not clear from the docs what is exactly expected to work "out of the box", so I'm hoping I can get more direction here. What I'm trying to do: Simply extend the user object with a field. ```export const auth = betterAuth({ database: drizzleAdapter(db, {...

Refresh Token Rotation with NextJs

Hey everyone! We have been using better-fetch with a custom auth plugin to handle attaching a bearer token to each request to our backend, and it's working great. However, I was wondering if anyone has had to deal with setting up a refresh token rotation within a plugin? For example, if the request fails with a 401 status, how can I trigger only 1 call to my /refresh endpoint without race conditions to refresh the token and retry the request with the new token? Also, a related question is how would I sign out the user on the client if the refresh token was revoked / something else went wrong? Here's my current implementation (not working)...

listOrganizations params - docs are no help

Hi, on the server-side I'd like to grab a list of the organizations in the system. The docs don't really say what you can pass in, TS is one thing but is there a reason the docs are either light or non-existant?