Better Auth

BA

Better Auth

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

Join

bug-reports

help

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?...

Migrating users from supabase to better-auth, without downtime

Hi, I am trying to migrate from supabase auth to better-auth. We have a lot of users, and would prefer to do it without any downtime. It is okay for users to be signed out, but when signing in again, all of the supabase auth related data should be migrated. User ids should also stay the same. What would be the cleanest option to do so? I was playing around with database hooks. In user before create, I trigger the migration. It fails, because better-auth is trying to create the user later. Is it possible, to handle user creation on my own, by returning some flag?...

Add activeOrganizationSlug in session data

Is there a way to add the activeOrganizationSlug in the session data, cache it and access it through getSessionCookie or regular auth.api.getSession ?

How to access email in `verify-email` route when verifying email OTP?

I'm handling all my authentication server-side using SvelteKit. I have requireEmailVerification: true and trigger an emailOTP to be sent upon user creation. This sends a user to a /verify-email route where they can insert their OTP. However, my server here doesn't know the email address of the user so cannot verify the OTP because it doesn't know what user/email to associate it with. How can I best solve this? I thought of passing the email as a query param, but that's unsafe. Any tips? Maybe the one-time token? Problem is that user needs to have verified their email before they can log in....

Change email using OTP

Has anyone managed to let a user change their email using an OTP rather than a verify link? I was trying for a while but gave up, would love to see if someone has made it work.

[Admin Plugin] Default User logic

greetings, I started developing with nextjs a little ago and found NextAuth to be a pain, better-auth is by that, a lot better but one thing i cant get my head around is a default admin user. i made my site so that users can register themselves and login, but if i have no users, then no one can "become" admin or other roles becaues everyone who registers is only a "user" not an admin. Is there a way where i can say "first user who registers becomes admin" in some way? i am building a small non...

Best way to create an organization

I'm handling all my authentication server-side. Once a user is created, I want to create an organization of which that user is the sole owner and member. However, I'm curious about the most natural way to do this. A user fills in their details on the frontend and provides an org name. I was thinking it could be in a database hook for the user on the create method that's run after a user is created. But in that instance, I'm curious how I can get the organization's name passed to the backend so that I can use this database hook....

[ Stripe ] Is there a way to cancel a user subscription when the user deletes their account?

Hi, I've set up the Stripe plugin, all works as it should, users can subscribe to products, they can change and delete subscriptions manually. Now when a user deletes their account , if they don't manually cancel the subscription before deleting the account, the subscription is still present in the Stripe dashboard and money is still being charged. Is there a way to cancel the subscription using the plugin? Can't find any info in the docs on this, the client.subscription.cancel() fn redirects th...

Change Email Expiry

When a user with a verified email changes their email, they receive an email to their old email to confirm their email change, but is there an expiry setting for this?
No description

generateId

how does the auth.$context.generateId({ model: "users" }) work? how safe is it/what algorithm is it using?...

Where to pass `forceAllowId` ?

I need to customize the ID generation for the User table by passing an existing user ID instead of letting the system auto-generate one. I found the documentation at https://www.better-auth.com/docs/guides/create-a-db-adapter for creating a custom adapter, but the section about user ID generation is unclear:
additionally, it's possible to pass forceAllowId as a parameter to the create method, which allows id to be provided in the data object. We handle forceAllowId internally, so you don't need to worry about it.
additionally, it's possible to pass forceAllowId as a parameter to the create method, which allows id to be provided in the data object. We handle forceAllowId internally, so you don't need to worry about it.
...

Different server for auth and frontend

When sending a password reset email using the sendResetPassword function, how can I properly construct the reset link to redirect the user to my frontend application for password reset, while ensuring that the underlying authentication process (e.g., token validation) is handled securely by my backend, given that my frontend and backend (auth) applications are on different URLs? Why might this specific function behave differently from my other email-sending functions concerning callback URLs?
No description

Is it possible to define custom methods for storing and finding users?

I want to use event sourcing for my application. It is possible to hook into the database calls of better auth and take make it let me handle storing and retrviing users etc? Do I need to write a plugin for this?

Go backend

Hi all, I'm currently working on setting up authentication for both a web frontend (using TanStack Start) and a mobile app (Expo, though I haven't started on the mobile side yet). The project is set up as a Turborepo with shared TypeScript code, so ideally I can reuse the same auth instance across both platforms. However, I'm using Go for the backend for various reasons, and I’ve run into two main issues:...

Auth endpoints returning 404 behind Cloudflare Tunnel

Hi there! I've just made my first Better Auth website using SvelteKit. I'm trying to now set it up on my domain through a Cloudflare Tunnel to my home server. I've followed the SvelteKit guide for setting up Better Auth and it worked while developing when the auth URL in the .env file was set to my local IP. However, when I set up the Cloudflare Tunnel, set the better auth url to my website's public URL, then try to interact with any of the auth endpoints, I just get 404s. I can see in the server console:
Not found: /api/auth/get-session
Not found: /api/auth/sign-in/social
Not found: /api/auth/get-session
Not found: /api/auth/sign-in/social
...

organizationClient incompatible type on Vue

I'm on a fresh quasar projects using Vite with pnpm workspace. My code is: ```ts...

Help: banUser expects string userId but my DB uses number — what's the best way to handle this?

Hey folks 👋 I’m using authClient.admin.banUser from BetterAuth like this: `const bannedUser = await authClient.admin.banUser({...

`emailVerified` as datetime

Is it possible to have emailVerified as a datetime column? I have tried with database hooks, to change the data before and after, but without any luck 😄

error thrown in better auth plugin is not captured by better-auth configured logger

I’m trying to use Better Auth in a Fastify application Below is the part of my configuration: const betterAuthOptions: BetterAuthOptions = {...