Better Auth

BA

Better Auth

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

Join

bug-reports

help

Multi-tenancy with drizzleAdapter

Hi everyone šŸ‘‹ I'm working on a multi-tenant application where the database (Postgres) is determined based on the current domain or subdomain. I've customized the migration workflow so I can apply the same migrations across multiple schemas or databases — that part is working fine. Now I'm facing an issue with the drizzleAdapter used in authentication. The current implementation connects to a fixed schema, but in my case, I need it to connect dynamically based on the current tenant....

Authclient SSR

I'm very confused, can you help me? I have a Hono backend application and I use nextjs for frontend purposes. I query the session in SSR with authClient.getSession. I solved the issue of the session not coming without adding headers to the fetchOptions section. However, when I publish it, the SSR session query that works locally stops working. What could be the potential cause?...

TypeScript Error: Extended Core Schema’s isAdmin Not Recognized on User

I’ve extended my Core schema to add an isAdmin: boolean flag to the User type and included the same ā€œmac and resolveā€ middleware in my app to enforce admin checks. The application runs perfectly and correctly verifies a user’s admin status at runtime, but TypeScript still complains that user.isAdmin does not exist on type User. Has anyone encountered this before? What am I missing in my type declarations or module augmentation to get TypeScript to recognize the new isAdmin property? Any help would be greatly appreciated—thanks!...
No description

How to persist next-intl locale during social-provider sign-up?

I can’t figure out how to reliably save the user’s locale during social-provider sign-up (Google, GitHub, etc.). My app uses next-intl, so the locale is always a path param (/en/…, /cs/…). With email+password I simply send locale in the body, but OAuth redirects lose this value. Current attempt Client (Next.js 15 + better-auth 1.3.2):...
Solution:
Solution: ``` if (ctx.path.startsWith("/callback/")) { //Here just use a /callback/ to catch all OAuth routes const newSession = ctx.context.newSession ?? ctx.context.session; if (newSession) {...

auth in distributed system

i wanted to build a distributed system with a standalone auth server that is used by both my hono api and nextjs frontend, since im using a monorepo my plan is to create a shared auth package with auth server and client instances, then create a separate hono server that uses the auth server instance for handling requests, and then the same auth client and server instances can be used in my api and frontend wanted to know if this is a good mental map or there would be some better apporaches to this...

403 User is not part of organization

I calling with authClient.useListOrganizations()all my organization but when I want to set one as active I get an 403 with message User is not a member of the organization. I checked in my db the users as well and he is part of organization. Do i miss something? my snippet: ```js...

Discord integration problems.

Hi, I’m having an issue with integrating Discord with Better-Auth. In my app, I have the following logic using authClient.linkSocial: ```ts const handleLinkDiscord = async () => { try {...
No description

Limits field in stripe plugin?

In the example in the docs there's a limits object with projects and storage. Those are the only options. What limits is it referring too?
No description

Verification table not populating

I am unsure what is happening at the moment but my emailVerification process works as intended except for it not populating a new row in the verification table. I'm not sure what would be causing this issue as I used the drizzle-kit to generate the schemas. ```js emailAndPassword: {...

How are built-in API endpoints / routes enabled?

According to the docs when using emailandpassword on the server one can use the endpoint /sign-up/email, https://www.better-auth.com/docs/authentication/email-password#sign-up. So when I Hono is set up, like in the bun-hono-better-auth project, https://github.com/ProMehedi/bun-hono-better-auth/blob/main/server/src/server.ts // Better-Auth - Handle all auth routes app.all('/api/auth/*', async (c) => { return await auth.handler(c.req.raw) })...

TanStack Query + Better-Auth

Do you guys use TanStack Query with Better Auth? I use it as my async manager for my own api calls. But was wondering if I should with better-auth authClient calls? Wrap it in TanStack Query? Cause I would use its cache invalidation for queries when mutations were done. Without it, idk how to handle authClient queries being fetched again on mutation....

Write custom plugin for telegram bot

Hey guys so i wanna support telegram plugin Dunno where to start from or how tg works I just have a simple bot and i wanna be able to login/signup using user chat id ...

Integrate Google login with 2FA

Hello everyone, I am currently working on a dashboard app of a company, and they want a more secure way to login when staff login their Google account, maybe face recognition or some ways else. And I wonder is it possible to use 2FA plugin with Google's OAuth login? I just check the docs and it seems to work with credential login Just want to know is it possible to acheive integration 2FA with Google OAuth login?...

Export disappeared

import { type UserWithRole } from 'better-auth/plugins';
import { type UserWithRole } from 'better-auth/plugins';
This export suddenly disappeared from the library, why did it get private?...
Solution:
I'm not sure why it got private, but I do think it's better practice to use the inferred User from your auth instance as that should include role if you're using the admin plugin

Custom error when user has a Google account but no credentials account.

Hey all! I have a small problem with my app. How can I show the user that they can't log in with email/password because they already created an account using Google? Thanks!...
Solution:
this could be achieved with db hooks https://www.better-auth.com/docs/concepts/hooks...

Tauri (or Electron) auth advice

I'd like to get opinions about auth (using better-auth) If there is no option to use Cookie session, would you say that storing JWT (instead of cookie) in local storage is safe or unsafe? I spent a lot of time reading articles and digging this with chatgpt and claude, but so far I got only vague solutions It's said that keeping JWT in local storage is prone to XSS, yet I have seen countless applications that do that, like nobody cares...

role assignment during registration

Is there a recommended way to handle role assignment during registration and then have an admin approve or reject that role before the user can access their dashboard or permissions? Any advice, best practices,...

Magic lInk

I have never set this up before so I am a little bit confused about how to implement it. In the docs it says to have a server.ts and from my understanding this is just your regular auth.ts file you initially create when setting up better-auth? Then we would have something like resend or nodemailer and a server action that actually gets your email address from the form itself and send out a link to login? Or am I over complicating it for myself. Any help here would highly be appreciated...

Session from MCP call

I have a function on my server code that automatically filters by logged user. That's easy with const session = auth.api.getSession({ headers }) and from there I grab the userId Now I want to call the same function but from an MCP server. This time session will be undefined. I see I can use auth.api.getMcpSession({ headers }) to get the userId from an MCP call and this works fine....