Better Auth

BA

Better Auth

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

Join

How do I seed users for development env?

Hello 👋 -- The title basically says it. I'm using prisma as my database adapter. How do I correctly seed users for development purposes? Do I import the auth and use auth.api.createUser({...}) or should I use my prisma client to directly insert? I have email verification enabled and I obviously want to skip that for this purpose. What's the idiomatic approach for this? Thanks in advance!

Bearer headers not returning even with CORS configured

First of all, thank you for the amazing lib! I'm trying to setup a react SPA using Vite and run the authentication using the bearer plugin but can't seem to make the authentication work. My backend is a Hono server hosted elsewhere, which I've configured as follows: ```javascript // auth.ts betterAuth({...

Getting so many errors related to mongo db

I'm trying to use better auth in nextjs I'm currently learning so most probably my mistake but what can someone please explain I'm using mongo db adapter and email password It is a test project to learn better auth before implementing on main project ...
No description

Issue: 307 Temporary Redirect After Sign-In in Production

To Reproduce 1. Deploy the Next.js app to Vercel. 2. Deploy the Hono API to Cloudflare. 3. Attempt to sign in....

Nuxt 3 SSR Client and Hono Server issue.

I have a Nuxt 3 ssr enabled FE which I am not using the server API instead I have a separate BE with hono js. While integrating the better-auth/vue client for SSR ```...

Refetching session for additionalFields change

Hey, I added an additionalField to my session called activeProjectId. I didn't find something to update the session from the official API. So per a Discord conversation I update it via my ORM....

Set the correct Typescript type when using plugins

I'm using the admin and organization plugins from better-auth/plugins. I'm explicitly typing by betterAuth instance as ReturnType<typeof betterAuth>;, but when I try to access one of the API provided functions, e.g. betterAuth.api.listUsers, TS warns me it doesn't exist. What is the correct typing for my betterAuth instance?...

DrizzleThe model "verification" was not found in the schema object. Please pass the schema

I just followed the installation + sveltekit guide. Clicking the login action gives me a 500 on http://localhost:5173/api/auth/sign-in/social Server error is ERROR [Better Auth]: BetterAuthError [BetterAuthError: [# Drizzle Adapter]: The model "verification" was not found in the schema object. Please pass the schema directly to the adapter options.] { cause: undefined...
Solution:
okay well import * as schema from '$lib/server/db/schema'; was actually enough to fix it. im still a bit confused about the error. i dont think i made any changes to the very default setup...

Forget Password endpoint always returns status code 200

When I call the forget password endpoint on both postman and my next.js app, I always get status code 200, no error, even if the user doesn't exist. In my next.js logs I can see the user not found error being registered, but my code which looks like this: ```ts async function onSubmit(event: React.SyntheticEvent) { event.preventDefault()...
Solution:
I would say for security
No description

Next.js [Admin] [Username] listUsers() returns UserWithRole[] missing property `username`

I'm using two plugins, Admin and Username. I'm currently building my admin dashboard and I'm listing all users in a server action like this: ```ts...

Retrieving session after magic link signin in Expo

Hi guys, We've set up Better Auth server in our nextjs app and created a successfull authentication setup. Now we're trying to use that same setup for our login on our Expo mobile app. For both the platforms we use a magic link. I've followed the setup here: https://www.better-auth.com/docs/integrations/expo with a custom server. I've managed to create a succesful login and deeplinking in the app based on the callback url looking something like this: http://localhost:3000/api/auth/magic-link/verify?token=super-secret-token-here&callbackURL=exp://192.168.1.60:8081/--/customer/(tabs)/home But when the app navigates to that screen and I call auth.useSession(), the session is always null. Does anyone have a clue on what I'm missing?...

What info does server getSession need?

Hi folks, I am trying to use Elysia with my Vite app. All the "provided" endpoints that pass through the basic middleware like sign in work: ```ts async function betterAuthMiddleware(context: Context) { return await auth.handler(context.request); }...

Setting cookies in electron with better-auth

I have my app properly setup to successfully redirect to an external browser to login with twitch in my electron app. I was able to successfuly get the callback to redirect back to my app, however the cookie doesnt get set. I have tried to manually set the cookie myself, but cant figure out how to get the second half of the token that is set. Any help would be greatly appreciated thanks!

Using BcryptJS with Better-Auth

Hi everyone, I’m looking for an example of how to use BcryptJS with Better-Auth. I have existing users with bcrypt-hashed passwords, so I need to configure the password option properly for both hashing and verifying passwords. The documentation mentions:...

Accepting organization invitation flow

Do you guys have any recommendations for using better-auth's organization invitation with users who haven't got an account / aren't signed in? I check on the frontend's page for accepting the invitation if there isn't a session, and if there isn't, I redirect them to the sign in page with the email already set and the input disabled Then once they log in (e.g. with OTP), then I use the hook to check if the user is new, and if so, it accepts the invite automatically if there is one, and if they already had an account and are logging in, I want to redirect them to the invitation page again Problem is, my backend and frontend are on separate domains so I'm getting CORS errors if I do the redirect...

Open Social SignIn in external window

Is there anyway to specific the location of where the signin window should open? I'm trying to integrate better-auth into electron and would love to open the auth window in the user's browser instead of within the electron window.
Solution:
Answered my own question. Add disableRedirect: true to the signin options, then redirect manually const { data } = await authClient.signIn.social({...

Merging Existing Drizzle User Table with Better Auth Core Schema

Hi everyone, I’m working on integrating Better Auth into my project that already uses Drizzle ORM. I already ran my migrations and created my custom User table using Drizzle. My table (defined in schema.ts) includes columns like first_name, last_name, and email_address. Now, I’m trying to merge Better Auth’s core schema with my existing user table to have a unified user record. I would like to map Better Auth’s expected fields to my existing columns. For example, I've configured it to map emailVerified to my custom column email_verified instead of the default. ...
No description

OAuth Proxy plugin not working

OAuth proxy is not working in local and preview environments. I've - configured the github oauth app with the production url - added oauth proxy plugin - added redirectURI to the social provider config But still getting the error in the image. My auth config is as below:...
No description

seesion not saving when running dev server with --host or when running build

Frontend spa in react Backend is a express server Hi, I am tryint to test my webapp from my phone so i am using the --host option with vite (i do bun run dev --host) but now my cookies are not being set and the session is not being stored. Here is my signin code: ``` const { error } = await authClient.signIn.email({ email,...
Solution:
Solution was using bearer plugin and making sure my auth server was actually hosted to the network. for future reference if anyone needs

Getting Error on Netlify Edge Functions (SvelteKit)

I recently migrated to Better Auth It works fine on node environment (on netlify) but It gives error on Netlify Edge Functions ``` Feb 18, 11:40:16 PM: 01JMD41S error [render] 2025-02-18T18:10:16.656Z ERROR [Better Auth]: ReferenceError ReferenceError: Buffer is not defined at Object.verifyPassword [as verify] (file:///root/.netlify/edge-functions/render.js:21057:58)...
No description
Next