Better Auth

BA

Better Auth

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

Join

bug-reports

help

How do we update custom session data without a full page reload?

In my Better Auth Next.js apps, I rely heavily on the custom session plugin to load user-specific data, keeping server and client in sync. However, I'm struggling with how to update this session data without a full page reload, as I want to avoid resetting client state unnecessarily. authClient.useSession() doesn’t seem to support live updates to custom session data. Right now, I copy that data into a custom context and manage updates there, but that forces me to use my own context for auth acro...

Typescript not seeing role as a valid attribute

I'm trying to check if a user is admin in order to access admin only pages. To do this I have this code, it works fine. ```js const session = await auth.api.getSession({...

Nestjs Prisma

Hey. Im using nestjs with prisma adapter, but im getting a server error when i try signing up with oauth github. SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'verfication'). i added to screenshots, one is my better auth config and the other is prisma client init.
No description

SERVER_ERROR: error: relation "ssoProvider" does not exist [ExpressJS and NextJS]

Hello, I'm currently struggling to get the SSO working because of "bad" integration with postgreSQL i assume? Every postgresql table needs to have a schema. My API is connected to a specific schema, but even publishing this table in all schemas it does not work. ...

API Key Plugin: Fields marked as 'Optional' seem to be required

Hi, we're attempting to use auth.api.createApiKey with the API Key plugin. We didn't add some of the optional fields (the ones marked optional in the docs: https://www.better-auth.com/docs/plugins/api-key#schema). We've been getting the following error: [Error [BetterAuthError]: The field "start" does not exist in the "apikey" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".] { cause: undefined }...

ERR_NAME_NOT_RESOLVED

I am running an app in a docker container with a backend in express and frontend in next. I am getting the following error when trying to sign in:
POST http://admin-portal-backend:3001/api/auth/sign-in/email net::ERR_NAME_NOT_RESOLVED
POST http://admin-portal-backend:3001/api/auth/sign-in/email net::ERR_NAME_NOT_RESOLVED
My auth config seems to be correct, with the trusted origins on both the client and backend auth setup pointing to eachothers container respectively, and when my user session was kept from a previous sign in i was pushed to the correct page but trying to sign out i got the following error:
http://admin-portal-backend:3001/api/auth/sign-out net::ERR_NAME_NOT_RESOLVED
http://admin-portal-backend:3001/api/auth/sign-out net::ERR_NAME_NOT_RESOLVED
What can cause this issue? Some server logs i see are: ``` admin-portal-backend | GET /api/auth/get-session 200 9.419 ms - - admin-portal-backend | OPTIONS /api/auth/sign-in/email 204 0.314 ms - 0 ...

I'm trying to disable setActiveOrganization except in very specific workflows.

Org Admins can impersonate users, and then setActiveOrganization lets them bleed into other programs. I have a VERY hacky workaround that might or might not work, but I would much rather only let the user set an organization at the moment of login, from a server perspective. I added this https://github.com/better-auth/better-auth/issues/3852 but second-guessed myself that maybe there's another way to do it. I'm using a custom imitate() plugin and not the admin plugin because I wanted further restrictions on the imitate process....

how to check if i'm impersonating an user

basically i want to make an impersonate feature where admins can see the user's dashboard (basically impersonation) but idk how to check if I as admin am currently impersonating someone....

how to set cookies on localhost

so i have a distrubuted setup with a universal server that is used by my nextjs frontend and hono + trpc backend, my nextjs app also sends cookies to the api, however with the current setup i have to run the auth and api server locally even if im planning to do changes only to the frontend, i tried implementing bearer plugin and it works well when i have to send cookies to a diff domain however on the initial authentication the cookie is sent via Set-Cookie header and is thus not automatically s...

Expo with React Server Functions

Hi everyone, I'm struggling to see a way of making BA work with React Server Functions. The BetterAuth API methods require a Request header, but in Expo React Server Functions there doesn't appear to be any way to access the header. Am I missing something?...

Admin plugin: admin_session cookie is not removed after ending impersonated session?

Hi! I am using the Admin plugin to implement user impersonation. I noticed that the admin_session cookie is not removed even after stopping the impersonated session. Is this intentional? Naively, I would expect this to be cleared after ending the impersonated session.

only creating single session per user

I guess my first question is, under what circumstances will another session be created? I am signing in using a different tab, but I'm on the same device. Only one session is being created, here's the current flow of what I'm observing: ``` Sign in on Tab 1 > Session created Sign in on Tab 2 > Session (from Tab 1) removed > New session created...

Mongo Adapter and API-Key plugin fail to find user

My application supports both Drizzle (postgres) and Mongo. When using the Drizzle adapter I have no issues with the API Keys but when using the Mongo adapter, it never finds the user with the error below. Note, that I am using a custom generateId function but again this has no issue when using Drizzle.
{"code":"THE_USER_ID_FROM_THE_API_KEY_IS_INVALID","message":"The user id from the API key is invalid."}
{"code":"THE_USER_ID_FROM_THE_API_KEY_IS_INVALID","message":"The user id from the API key is invalid."}
Any thoughts on this are appreciated....

Email OTP Sign in/Sign up

Hello! I’d like to use email-based OTP for both sign-up and sign-in (without any email/password), but the current signIn method only returns the token and user object—it doesn’t actually return a session cookie. I discovered that calling verifyEmail() with (overrideDefaultEmailVerification: true) will automatically sign the user in, but it only works for existing accounts and doesn’t create a new user. Is there any way to handle both cases? I checked the documentation but couldn’t find a way to exchange the token i get from the signIn method for a session cookie directly....

SSO Unable to do SAML registration

I try to fill in the data for registerSSOProvider according to this guide https://www.better-auth.com/docs/plugins/sso#register-a-saml-provider, But I get 401 Unauthorized. please help me with this this is just a flow I'm currently testing on local environment. As I understand I need to call this function before my app is deployed, so it will know which SAML provider that my app is working with, but for local I just call it every time user need to authenticated. Is my approach correct?...
No description

Typeerror: Invalid url. magic link issue

Hi, I've suddenly got this error only in development where ctx.context.baseURL is undefined. Whenever I edit the auth.ts with manually defining baseURL and removing it it suddenly does work. I am using sveltekit...
No description

how to reduce db queries

```bash GET /organization-os 200 in 2450ms Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"] Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"] Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]...

Organizations Plugin Help

I'm struggling to adapt the organizations plugin to my use case, which requires dynamic roles and permissions created at runtime by users. Since the plugin seems designed around static, compile-time roles, I'm constantly fighting against its architecture. I've tried: Built my own RBAC system to integrate with the plugin Considered using metadata to bridge the gap between static and dynamic roles...

have anyone tried login using instagram?

have anyone tried login using instagram?

Why few keys in redis has no TTL?

Hey im noticing many keys are there in redis which has no TTL, so it stays forever, session information will be expiry after 30 days, Im using secondary database as redis by passing secondaryStorage: { get: async (key) => {...
No description