Better Auth

BA

Better Auth

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

Join

bug-reports

help

Lichess.org PKCE gives oauth_code_verification_failed

Can you help me debug this issue? I'm trying to link an account to lichess.org via OAuth with PKCE using a genericOAuth provider but I keep getting this error oauth_code_verification_failed on better-auth. SETUP...
No description

Hono + Better Auth NOT_FOUND Error on Auth Endpoints (e.g., /api/auth/sign-up)

Hey everyone, I'm setting up an authentication API using Hono.js, Better Auth, and Prisma with PostgreSQL. I've followed the recommended setup and folder structure. My Hono app mounts the authRouter (which handles Better Auth's auth.handler) at /api. So, endpoints like registration are accessed at /api/auth/sign-up....

ElysiaJS setup fail

I've tried betterAuth twice and always give up as I fail to get it working. I'm using Prisma ORM and just email and password for now, I've set up the betterAuth middleware (mount and macro) and added the catchAll routes under /auth/* Debugging shows me that the routes are being intercepted by betterAuth but nothing other than that happens, Generating the schema throws some long error I don't understand....

Failing to create user

is there a way to debug this error I'm getting while creating a new user: { "code": "FAILED_TO_CREATE_USER", "message": "Failed to create user",...

Google LinkSocial Additional Scopes

Hello! I am using Google Oauth as a provider and attempting to follow the documentation to allow users to add calendar scopes after the login, the below correctly adds scopes, but once a user logs in with the standard oauth again that overwrites the additional scopes. I've been trying to debug this for a bit but can't figure out if there is supposed to be standard better-auth management for this or if I need to add some hook to the database to make sure we don't overwrite the scopes. Tahnk you! ```{typescript}...

Authenticate /pages/api route

Hi, i am trying to protect my websocket connections by verifying if the user/client is logged in or not. Usually i'd use the getCurrentUser function: ```ts "use server"; import { auth } from "@/lib/auth";...

How to figure out if subscription is canceled on trial

One confusing aspect of subscription object is when a trial is canceled, it only shows trialing state rather than cancelled-trial or similar status which makes it hard to show a cancel or resume button since I don't know if user canceled their trial or not.

Seperate API authentication for NextJS

Hey guys! I am working on an app in NextJS and I want to add a few API Endpoints that I want my users to be able to use via API endpoints. How would I enforce an API key based auth only for the API routes while keeping my email/password auth on the other parts of the site?

Generate magic links without sending

Hi guys! I have this use case where I want an admin to be able to generate magic links for other users and send them as the user wish. Can't seem to find a way to do this. Any help is appreciated 🙂

additionalFields suggestion in swagger

is it normal i don't have this extra fields in my swagger suggestion ? note: it does work when i write manually....
No description

how to management active organization between session tabs

hi, I’ve been trying to understand how I can management my active organization between session tabs I know I can set my active organization in my user session, but, If I handle with multi-tenancy in tabs, this will not be useful ...

Session doesn’t get invalidated after the user is deleted

I tested what would happen if I deleted a user manually from the database and when I refreshed the page it stayed in the same page, it didn’t redirect to the auth page. I tried using these 2 method in the middleware: - https://www.better-auth.com/docs/integrations/next#for-nextjs-release-1517-and-below - getSessionCookie() and got the same result, it thinks the session still exists, also the better-auth.session_token cookie doesn't get deleted either. How to solve this issue? It’s been a day and I still haven’t figured it out. Any help would be appreciated!...

Migrate command doesn't work

I'm using Supabase. I have been following the installation guide, and so when it comes to run the migrate command, I run it, it asks me about installing the package, then nothing. I can't see any new tables in Supabase.

Include relationship in session.user object?

Hey there 👋 I'm looking to perform a check in a Next.js layout that sees how many related posts records exist for a user before redirecting or granting access. Now, I could just denormalize the count of these records into a column on the user record, but maybe there is another way. ```ts import { customSession } from "better-auth/plugins";...

Pure postgresql with better-auth

Hey folks, is there an example on how to use better-auth with pure PSql locally? Im having troubles alone
Solution:
all good, either to simplify your life when setting up the project or just to keep everything together, a lot of people deploy using Docker

Best practices for a monorepo that needs to share sessions across apps? Next.js multizones

Has anyone ever implemented better-auth in a Turborepo monorepo that needs to share auth sessions across apps? I'd love to have my 2 monorepo apps at /feed and / be able to share session state. When someone logs in to one, I also want them logged in to the other, etc. Seems like this could be achieveable with Next multizones since they'll be on the same domain, but not sure how best to approach this from better auth. Maybe an auth package also in my monorepo?...

How to add custom fields on Sign-up?

How do you add custom fields to client side functions like sign-up? I am working on a sign-up form in nextjs app router and I have better-auth working with the basic email, password, name, etc. fields using: const { data } = await authClient.signUp.email(...

stripe plugin & Polar plugin for payment

if i use stripe plugin & Polar plugin tgt , will there any problems?

Cannot verify TOTP after successfully setting up 2FA, getting `INVALID_TWO_FACTOR_COOKIES`

I can successfully enable TwoFactor, show the QR and backup codes, and verify it with a generated code. This sets twoFactorEnabled to TRUE for the user. However when that user later logs out and back in, and needs to verify their 2FA TOTP code, I get this error INVALID_TWO_FACTOR_COOKIES. No two factor cookies are being set anywhere, and I have tried to log them but they aren't generated by the enable nor verify TOTP in my totp/setup routes. What could be the issue? Thank you....

how to listUser from admin plugin?

I'm having trouble listing the users of my application using the admin plugin, I used the code provided in the documentation but I'm still having trouble.
Solution:
On the server, you must use auth.api
No description