Better Auth

BA

Better Auth

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

Join

bug-reports

help

custom type in additionalFields

is it possible to use custom type in additionalFields?
Solution:
We provide set types and that's all the supported for our adapters.
No description

Centralized auth

Is there any way to have multiple (NextJS + Hono) apps, and a centralized auth one? So every app redirects to auth.example.com and gets the auth form from there and authenticates in there? Thanks in advance
Solution:
so you will have one instance on server either of the server framework and client frameowrk to create a client instance separetly so that they can make a request to server with through better auth client abstraction

useSession weird behaviour

Hi, I have some problems with useSession, it keeps giving me date null even though I am logged in. I'm testing it with dev and turbopack. This happens when I do a page refresh, so if I logout and log in the hook works, but if I do a page refresh it no longer works returning null. auth-client.ts...
No description

List of endpoints?

Can’t seem to find it, but just looking for a list of endpoints that better with exposes by default?

Can I use better auth as authentication layer between hono backed and next js frontend?

I'm building platform that has hono js as backend, next js for web app, expo for mobile, prisma for db within turborepo. I'm using nextjs server side data fetching so I have to check authorisation on server side of next js. I know this case is too much complicated. Please if you have any near examples or suggestions, It would help a lot....

The table `main.verification` does not exist in the current database.

hey - trying to use better-auth with hono on cloudflare pages, currently just with a local database. Got hono and the database talking, tried to add better-auth with prisma, and I'm getting the following error: ``` <-- POST /start-sign-in /start-sign-in sees email user-email@email.com...

Stripe + Organisations

Hey there, first of all great job on better-auth. Love it! Is there any plans in being able to use orgs as the holder of stripe_subscription id? We're using orgs as "tenants" and it would be weird to store the stripe subscription id on the user object, since everything else is related to orgs....

Legal terms compliance

I added a terms of service and privacy policy acceptance checkbox to my sign up form. User accounts cannot be created without checking this box, however the acceptance is not stored in the database at all (e.g. no timestamp, hash/version of the accepted terms documents, etc.). Does anyone know if this is sufficient, legally compliant with e.g. GDPR or do I need to store acceptance information in the database? I did see some discussion about this in this discord server, but not much about legal compliance in the first place. If it's sufficient to not have to worry about storing this info i'd rather take the simpler path! Relevant GDPR section: https://gdpr-info.eu/art-7-gdpr/...

Get user inside session hook

Is there a way to get the userinfo inside a before session databaseHook? I can't call auth.api.getSession and then read the user object as its in the initialization of auth. My goal is to automatically set the active org based on the email domain. ...

Unknown argument `stripeCustomerId` when creating customer on signup

Hey, I'm having a new issue where updating the user's stripeCustomerId automatically on signup, gives me a prisma error. I found an other thread here where the issue was the schema not having stripeCustomerId set as optional, but my schema does. Has anyone else had this issue?
Solution:
ok yea it was my fault. I got a warning from prisma to set an output path for the generated client Warning: You did not specify an output path for your generator in schema.prisma. This behavior is deprecated and will no longer be supported in Prisma 7.0.0., but then forgot to change the PrismaClient import statement from the old default path.

Handling better-auth.two_factor cookie after TOTP verification and logout

Hi there, I’m using Better-Auth with TOTP-based 2FA and had a question about the better-auth.two_factor cookie behavior. I’ve noticed that after a user successfully verifies their TOTP code, the better-auth.two_factor cookie remains present in the browser — even after a full session is created. Similarly, it doesn’t appear to be cleared when the user logs out. This leads to a UX issue where, after logout, my middleware sees the cookie still present (but no session), and incorrectly redirects users back to /verify-2fa instead of letting them hit /....

Expo plugin isn't a valid plugin

Just set up an external backend for my app and for some reason the expo plugin from import { expo } from "@better-auth/expo"; isnt compatible with the type BetterAuthPlugin. Error: ``` Type '{ id: "expo"; init: (ctx: AuthContext) => { options: { trustedOrigins: string[]; }; }; onRequest(request: Request, ctx: AuthContext): Promise<{ request: Request; } | undefined>; hooks: { ...; }; }' is not assignable to type 'BetterAuthPlugin'....

Trying to make my plugin work as npm package with bun

Hello everyone, I built a better-auth plugin. It works perfectly when I use it directly in my app. But it doesn't work when I try to put it as an npm package. I tried to bun link it with
bun link my-plugin
bun link my-plugin
and copied the way @better-auth/stripe handles it. But it still gives me this error: Module not found: Can't resolve 'my-plugin'...

something worong with cloudfalre

Hi everyone, I'm encountering an issue while deploying my Next.js project to Cloudflare Workers using OpenNext, and I'm also using better-auth for user authentication. I'm getting the following error: ```json...

Exploring Better Auth SSO Plugin – Guidance on authClient.sso.register Usage

I’ve created a sample repository to explore the usage of the Better Auth SSO plugin. While working on it, I was unsure about the appropriate placement and timing for calling authClient.sso.register, especially since invoking this API requires an active user session. Additionally, there is no implementation provided for signInWithTestUser, which added to the confusion. Documentation reference: Better Auth SSO Plugin - Register an OIDC Provider...
Solution:
so the sso plugin is meant to be used by allowing users to register a custom provider that can be used later to authenticate user

Multiple apps sharing the same database using Better Auth

Hello! You guys are doing some awesome stuff with this framework. I am wondering if it is possible to have the following setup:...

organization plugin for "embedded" use case (no user login)

Simple example to understand my question better. You have a restaurant and a few ipad minis. now each staff gets an ipad. instead of requiring the staff to create an account and be invited, id want that the admin can create a staff "with just name" and then generate like a magic link that logs you into a session with the correct permissions. Is this possible? any tips to get on the right track for this? Currently im assuming i just need to create an account for them with some fake email and random password they will never use...

How to manage 2FA Trusted Devices?

After marking a device as trusted in 2FA . How do you: * get all previously trusted devices and * Remove an older device from the trusted list...

how to use kysylo-adapter with better-auth

i want to write t3-app with kysylo and better-auth. but i found i can't use kysylo-adapter.

[OIDC] federated logout (`end_session_endpoint`)

Does BA implement the OIDC standard end_session_endpoint in the OIDC provider plugin for federated (RP-initiated) logout use cases? Section 2 "RP-Initiated Logout" in the spec here: https://openid.net/specs/openid-connect-rpinitiated-1_0.html...