Better Auth

BA

Better Auth

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

Join

bug-reports

help

Question about how to apporoach data

Hello, I have a question on how I should approach BetterAuth and handling its data. I am making a website with account features (name, email, address, phone number, etc...) and I don't know to structure my additional fields. 1) Do I put additional fields in User or into a seperate UserProfile?...
Solution:
1. Anything associated with a user can be in the user table, meaning it's fine to put it in the user additionalFields. 2. Depends on your app and how accessible you want it to be, but also keep in mind that getSession/useSession will be more secure as we check for session validation before returning the data, using your own endpoint to return data might be more work 3. There isn't any difference relating to Better auth on whichever you should use, comes down to preference & situation...

Questions about signup/signout in Next

The docs have this example code for email/password signup and signout: ``` // Signup import { authClient } from "@/lib/auth-client"; //import the auth client...

Bearer Tokens For Authenticating Requests to Backend (Express)

Hi guys! I am trying to implement the bearer tokens plugin so my backend can authenticate users requests. However, it seems that tokens aren't being set as explained in these docs: https://beta.better-auth.com/docs/plugins/bearer Our Infrastructure:...

How to utilize organization capabilities for both site administration and user organizations?

Hey there šŸ‘‹ I am curious if anyone has used the Better-Auth organization capabilities for both site administration (moderating content, deleting/suspending users, etc.) and also for user organizations (managing group-created content). Are there any points worth considering when doing this?
Solution:
I’m an idiot. Just use the admin plugin.

:question: How to Log In Programmatically as Any User (Super Admin Impersonation Use Case)

Hi Better Auth team šŸ‘‹ I'm trying to build a super admin panel where I can manage multiple organizations and their users. I already fetch the list of users and want to support a "Login As" feature — where I click a button and get logged in as that user (without needing their password). What I'm Doing:...

Better Auth with prisma/mariadb

When creating account (Google OAUTH), I am getting error: Argument createdAt is missing. ...

How to Efficiently Cache JWT in Next.js to Avoid 1.5s Latency?

Hey everyone — I'm using BetterAuth with Next.js and running into an issue where fetching the session and JWT (on the server) adds ~1.5 seconds of latency to every request. I'd love to know if anyone has a reliable and secure pattern to persist the JWT on the server that avoids hitting the auth endpoint every time. I've already tried storing the JWT in cookies, but it doesn't work reliably because the session changes when switching organizations — I'm using BetterAuth's organization system....

Authentication without access to DB

I have a architecture of a website, controller api (better auth server), and a bunch of daemons. Each daemon will receive requests from the website containing the user's better auth credentails. What's the best way to verify these?

Multiple Session Requests.

Are these many session request normal on first load a thing or did I mess up something? Like I have middleware and I guess it doesn't cause this so why tf are there so many session request on home page, even when there is no session fetched on home page. Or this is something related to dev environment ? Also on other pages it does around 1 to 2 fetches, but why does it do these many session request on home page always. Let me know If you wanna look at the code. I will share middleware below for now....
No description

Change password algo for the username plugin?

I understand that with emailAndPassword you can do this ``` export const auth = betterAuth({ //...rest of the options...

how to build on top of useSession?

Hello! As an exercise to understand client plugins better, I would like to add a useUser method to the auth client. All I want is for it to leverage the existing useSession and extract out the user data object without directly making a server call. I looked into getActions but don't see a way to access the current auth client object, i.e. something equivalent to the "this" reference in order to call useSession. Could someone more experienced in this let me know if this is possible and/or suggest an alternate approach? I'm currently using solidstart but suspect that the answer would be platform-agnostic. I can always define useUser outside of authClient but was wondering if it is doable via a plugin instead....

Modify User database creation

Hello! šŸ‘‹ I'm migrating from Auth.js (Next-auth v5). My project currently has an authAdapter with a custom createUser function, which creates an org for a new user. This means that my db has a column: default_org_id which is a required field. How can I modify better-auth's user creation behavior to add my custom org and Stripe creation logic? Additionally, how can I access this required field in the user passed in the customSession() function? customSession(async ({ user, session }) => { user.default_org_id } does not exist here. Thanks!...

Middleware causing infinite redirects

I've a different url for auth (backend) and frontend, here's the middleware i'm using, it's causing a request loop, gotta use only a layout auth

Creating user with emailOTP

I am using the emailOTP Sig-in Now, I want to simulate this on the server side, meaning that I want to create a client without sending the email and whenever someone with that email signs in they receive the otp to sign-in (basically creating an account for the user with his email)....
No description

request in the auth file in the server side

I'm using nuxt 3 and the stripe pluging I have this ```ts stripe({ stripeClient,...

How to use Better Auth with React Native CLI instead of Expo

I am searching through internet to find a way to use Better Auth in React Native CLI but got no luck. So, please help me with that? I have used Better Auth in many React projects but this time I eagerly want to use it in React Native CLI without Expo....

Include additional field in session data

Hello! I have an additional field username that I want to be included in the session data, but I don't know how to do it. ```tsx import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "./db/index";...
No description

Request gets stuck and timeouted after Captcha

Using the Magic Link plugin and Captcha (tried with both Cloudflare and hCaptcha with same outcome). The problem is that after successfully solved captcha and passing through the "sendMagicLink" method of magicLinkPlugin, my email request gets STALE for no reason and dies after request timeout. Funny enough that this only happens on local dev server and in production email gets delivered just fine. Without captcha plugin email gets delivered on dev server as well. I got into source code of the c...

Add more tables using neon.tech

Good afternoon, I would like to know how to add extra tables, I am using better auth with neon.tech (postgres) and I want to create a table apart from the 4 that come called submissions and that the user can upload feedback and relates to your user id. How do I do it? Can I do it using better auth and then I can get them with the npm package? or do I need to create a new independent call to neon to handle it outside of better auth?...