Better Auth

BA

Better Auth

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

Join

bug-reports

help

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?

migrate after docker build

Hello, I try to do something but, I don't know how to do that, I use better-auth on an express api, that I dockerized and I use gitlab-ci.yml to build the image on gitlab registry, then on my server I run a docker-compose.yml that pull the image from the gitlab registry. my probleme is that sometime, I need to make the migrations for my bdd, but, I need to do it on the runtime cause my image does not now yet the database credentials. but as I build the image I don't have the auth.ts file anymore, so run the better-auth migrate command inside my docker does not work. can someone give me some good way to deal with that ?...

Add id of relation to user obj

Is it possible to access the company id in the session user? ``` model User { .......
Solution:
Hello, you need to define an additional field in your auth config: https://www.better-auth.com/docs/concepts/typescript#additional-fields Then, you can access it via the customSession plugin: https://www.better-auth.com/docs/concepts/session-management#customizing-session-response...

Better auth issue with prisma adapter using with Nuxt

I have an issue when building for production (works fine in dev) with some Es module saying __dirname is not defined in ES module scope I have "type:module" in my package.json. can someone help me with this issue? I have my better-auth instance in lib/auth like this below `import { betterAuth } from "better-auth";...

Removing column

How can I remove this entire column as I am using firstName and lastName and I don't need it
No description