Better Auth

BA

Better Auth

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

Join

bug-reports

help

Need Help with Multi-Tenant, 2FA, and Role-Based Authentication in NestJS using BetterAuth

Hi everyone, I’m currently working on an SSO using NestJS as the backend framework, and I’m running into a few challenges related to authentication and authorization with BetterAuth. I hope someone in the community can point me in the right direction or share their experiences. Here's what I'm trying to achieve:...

Can I Add a User-Type Condition to the SQL WHERE Clause During Sign-in?

I have added a "role" field to the user model as follows. Is it possible to add a condition to the SQL WHERE clause to only include users with a specific "role" when signing in? I have looked through the documentation and source code, but I couldn't find a way to extend the SELECT conditions. Please let me know if there is a good way to do this....

CSRF with Next.js server directive w/ Backend Api

For CSRF to work (with Next.js server directive), so that the client requests get forwarded from the Next.js server to our BetterAuth backend API, do we need to manually forward all of the headers to the backend API?

Vite cannot find "react" import in the npm package

I'm implementing the svelte demo in my sveltekit app as a test, and when running vite server, this error occurs: ``` ✘ [ERROR] Could not resolve "react" node_modules/better-auth/dist/client/react/index.mjs:3:58:...
Solution:
Solved: The initial import of the library in the client was using "better-auth/react", needed to change it to "better-auth/svelte" to import the correct framework library.

Exclude role in the signup (frontend) as it should be driven from the backend

Hey Guys, I added the field role So i added this in React: export const authClient = createAuthClient({ plugins: [inferAdditionalFields({ user: { role: { type: "string" } } })], ...

oidc provider - Change issuer?

Is it possible to change the issuer at the oidc provider ? It defaults to the apps domain...

Update TypeScript types of the user ID table

Hello, I looked at different posts here and I understand that the ID from the user table can't be changed but I've modified my SQLite database schema to use an integer type for the primary id column of the user table (because I did a migration and I need to keep the IDs). ...

redirect after sign up, emailAndPassword

``` await signIn.email( { email, password, callbackURL: "/admin",...

Extending organization.create

Hey guys I'm trying to add something simple when creating an organization and was wondering if there was a way to do something like this ```typescript const response = await organization.create({ name: data.name,...

Middleware in a Better Auth Project

how the middleware of a project using better-auth should look? because i was using this middleware: ```tsx...
Solution:
We highly suggest using the middleware in next just to decide routing for a user and not the only place to check for auth. And fetching session from an api can make your site slow, since now you're running a server and a db on every call. I suggest checking for cookie and on the actual pages, checking for the actual session.

Create organization after singUp

I want to create Vercel like onboarding experience. What is the best way to create personal organization right after signup? I thought about using databaseHook after user creation but I can't make it work.

rbac / orgs / permissions

Hey guys, First off thanks for developing and maintaining this and congrats! Very nice. I'm new to auth systems and app development and need to confirm if your solution supports my specific multi-tenant app requirements for my app....
Solution:
Hey for maning perms, you have 2 options built into better auth. App level access control and org level access control. For app level access control, check out the admin plugins and for org level the organization plugin has something built in.

Admin to add users to their organisation

Hi all. I'm building out a Saas project in next.js where I will have clients set up as organisations and each client will have multiple users. I've implemented admin and organisation plugins, have created some organisations and created some users which is all good. The lead user (as an admin) can create other users but how do these new users get assigned in to the organisation? I have basic RBAC established so that only an organisations users can see data/ other users in that organisation.

Session type after using admin

Hello everyone, I just implemented admin plugin for role-based authorization Then I changed user's role type to enum How can I also make this change to session type return from useSession? By customizing session?...

Anyone have an idea what this bug is about

The inferred type of authClient cannot be named without a reference to ../../../../node_modules/better-auth/dist/shared/better-auth.Bi8FQwDD . This is likely not portable. A type annotation is necessary. I have added dom to tsconfig, cleared my node_modules and cache, updated to better-auth: ^1.2.4, as well. This is what I am trying to do, example from docs...

Tanstack Start Server functions cookie issue

Hi, I'm having trouble getting session_data cache cookie to update when I use the auth api inside a tanstack start Server function. It is similar to next.js I think, and I have recreated a version of the nextCookies() plugin for tanstack start. problem is it works perfectly in development server, but not in vercel/netlify deployment. can anyone confirm if they have the same issue or help? thanks!...
No description

Single Auth Multiple apps setup.

Hi. I am trying to setup a central auth which will be used by multiple apps. I tried creating OIDC but its not working good for me. I came across this comment. How should we go about this. I have nextjs central auth and tanstack start first client app. Do i need auth.ts in tanstack server api routes or only in nextjs central....
No description

How can I extend the organisation plugin?

I need organizations for my tool that have teams, where I can select the active team. It should behave similarly to how it works with the organization, but within the organization.