Better Auth

BA

Better Auth

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

Join

bug-reports

help

Does better auth supports Docker hosted local database ?

Helo I am suing docker, and Nexjt,s Here is my setup 1. I am using dockerized posttres which is running and working perfectly with prisma and I tested by seeding (inserting) some randomw data. 2. but when I connect to better auth it shows me one single error which is this below one ...
Solution:
Then I will work that and then I use better auth methods like signUp with email or other methods then it gives me that Errro. Did u do this and worked for you ?...

OIDC Plugin data migration

I have in my database the ids of the users from my previous authentication provider. I want to migrate these users to a my new better-auth backend so I can handle this data there. I've added a button where they can link the account and this is working perfectly. However, I wonder if I can migrate the users from the old to the new app, just with the users ids. I saw that in the tables better-auth saves some tokens, but not the id directly. So I would like to know if there's a way to do this migration, without the users to manually connecting their accounts again. Thanks for the help....

Error Code: email_not_found

Google oauth works fine, but we I try to login I get email_not_found error. Any idea why it happens? ```ts const config = { database: {...

Endpoint to Fetch Organization with all teams

Is there an endpoint to return all teams inside an organization? I want to get an object including the organization and its teams, like this: { "name": "lorem-organization", "slug": "lorem-org",...

The model "user" was not found in the schema object

I'm not sure what is going on, I've already specified it in the schema: ```ts export const auth = betterAuth({ plugins: [bearer(), jwt()],...
Solution:
Well apparently the TS output was originally /dist/app.js, but somehow - and I still don't know why/how, it started outputting to /dist/src/app.js, so basically I was 'working' on an older code.

Error when running nextJS demo app (Module not found: Can't resolve 'better-auth')

I'm trying to run the nextJS demo app, but getting this error after pnpm run dev I did the following steps per the README: ```...
Solution:
Got around it by changing package.json to import packages from npm rather than references to the mono repo's workspace: and catalog:.
No description

Redirect Ignoring baseUrl?

I have a next.js app, locally it all works fine but when I put it on a server with nginx for https, authentication (specifically Twitch) it redirects to localhost:3000? No matter what I do I can't point the redirect back to the SSL server. When I change stuff locally it comes up with some sort of cross origin error. I can't tell if I am missing something blatantly obvious...
Solution:
Twitch is just sucky, there is a captcha above the client ID which you need to click to enable the save button:
No description

Monorepo

Hey again guys. I have a monorepo project with hono server and nextjs frontend. Im trying to check the user session in RSC with authClient, but im geting null. Can someone explain to me why this the happeing. getSession return null while useSession return the user object.
No description

OAUTH Discord id_token Lifetime & Refresh Token Handling

I'm using better-auth with Discord OAuth2 and need a SpacetimeDB connection to persist longer than the id_token's 1-hour lifetime. Currently, I retrieve the id_token from orpc.user.getTokenId after initial sign-in. My issue is that this id_token expires, leading to Disconnects. Does better-auth handle the OAuth2 refresh token flow internally? If so, how can I access or trigger a refresh of the user's session and obtain a new, valid id_token without re-authenticating the user?...

how to handle multi-server environments?

let's say i want to use react server components with Nextjs but also Hono for api access. would i follow the setup instructions twice: for both next and hono? do i need to link them somehow?

Plugins or Drizzle + Next JS API

I’m developing an application similar to Linear.app, where each team contains projects with features like comments, rich text content, and customizable columns (e.g., "Urgent", "Working On"). The desired structure is: A workspace encompasses multiple teams. Each team contains multiple projects. Each project has user-defined customizable columns....

Is there a way to rotate bearer tokens?

Hey everyone, I’m using bearer tokens via bearer() plugin mainly for authentication on a mobile app. So far I implemented auth on my backend api level, which is then used by my mobile app to login, grab the bearer from response body and set in `authorization’ header....

Customize Session with User claims (roles)

Hi everyone! I’ve implemented Microsoft authentication (server-side with Next.js), and everything works fine. However, I’d like to add my user’s roles to the Better-Auth session, and I can’t figure out how to do it. ...

Trouble inferring types on client side (1.3.4)

@Better Auth Hey, I was trying to infer some types on client side: type AuthContextValue = { member: typeof authClient.$Infer.Member | null; user: typeof authClient.$Infer.Session.user | null; session: typeof authClient.$Infer.Session.session | null;...

cookies in ssr mode

I am using better auth with tanstack start (as my frontend) and hono as my separate backend for now, while every thing works fine without ssr mode when i switched ssr mode it becomes difficult to get the cookie in the ssr mode with better auth, i am using the below code snippet to fetch the user session but its not getting the cookie properly ``` export const getSessionServer = createServerFn({ method: 'GET' })...

How to make an "after" hook when using Google Sign in?

We have an after hook which does various things from a sign up survey the user submits. It works well when email and password is used. When the user selects Google sign up, then that hook never runs. It's something like this:...

RBAC in database

Hey! Do you guys have any guides or documentation on how to integrate better auth with RBAC loaded from the database?! The plugin is purely meant to have it code-only, right?!...

Spotify Login

Hello, i'm having trouble with Spotify login on my NextJS & tRPC app, basically the login with Spotify works in the sense that the user is created in the database without issues, but after the redirect back to my site, I’m not actually logged in — the session isn’t recognized in the frontend. I assume it might be a cookie issue, since spotify doesn't allow to use localhost as callback URL for safety reason, i chose to put my domain (actually a tunnel, but still), i'm really lost here, i'd appreciate any type of help! Note: api.samueledamico.com points to localhost:3001 (where the API is hosted)...
No description

Session type `auth.api.getSession` is wrong

When I do ```ts import { auth } from "@myworkspace/auth"; const { session, user } = (await auth.api.getSession({...

Expo Magic Link Deep Links Not Working As Expected

I'm not sure if I'm missing something, but after clicking the magic link in an expo app, the app deep links into the route provided in the await authClient.signIn.magicLink function, but the user isn't logged in automatically like on the web, nor do I see a way to manually verify the session because the token isn't a part of the callback URL (deep link). Is this a bug, or am I missing something?...