Better Auth

BA

Better Auth

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

Join

bug-reports

help

Hono Handler Not Triggering

I cannot get my hono handler to trigger right, even with app.all, or app.on. It always gives me a 404. Here is my main code: ``` import 'dotenv/config'; import { env } from './utils/env.js'; import { serve } from '@hono/node-server';...

React SPA redirects on signIn and signUp

In a React SPA when I call authClient.signIn.email({email, password} my whole page does a hard reload on success. Is this intended behavior? I couldn't find the source code where this happens (yes, im preventing default in my form). Also, when I do authClient.signUp.email({name, email, password}, {onSuccess: () => navigate({ to: "/" })}) my auth check with authClient.getSession() in my protected route always fails and I end up redirected in my sign in form. How do you guys solve this race condition?...

how to correctly type useSession on the client side

I'm using React and using the useSession hook that comes from authClient, the data type comes as const data: { user: any; session: any; } | null. I saw the correct values in the console. How can I correctly type the user and session? This is my first time doing this setup...
No description

Help Implementing Captcha Plugin

I was making a project using the captcha plugin and was using the cloudflare turnstile for it but can't find much docs on it on how to implement the plugin. Is there any example repo with turnstile + better-auth just a request to also add that in the docs, I could do that also but not able to find an example ...

Keep active organisation stored between refresh.

Hi guys, I noticed that when the user signs in, the active organisation is set to null, as per the documentation. Is there a way to bypass this? So that once a user creates an org, or signs in, it automatically sets their last used organisation to their active one? Not sure if this is achievable from the config, and if not, what would you guys suggest I do? Thanks...

RSC understanding difference auth/authclient

This might be s very, very dump question but I cannot seem to figure out exactly when to use auth.api.... or when to use authClient.... Could someone please simplify it for me? (Yes I have read the docs but I might have missunderstood it because of my dyslexia) 🤣...

CORS error when using Better Auth with subdomain (Next.js)

- Signin page: https://app.example.com/signin - API endpoint: https://example.com/api/auth/sign-in/social - Using middleware to rewrite subdomains (so app.example.com) ...

Issue generating auth-schema

@Better Auth ❯ pnpm dlx @better-auth/cli generate ⠋ preparing schema...file:///Users/coco/Library/Caches/pnpm/dlx/2630d1115258bcf0a385078b8f531124ceb8d54daa6ed354a6419c4761723963/198b27522a9-139f7/node_modules/.pnpm/@better-auth+cli@1.3.6_kysely@0.28.5_zod@4.0.17/node_modules/@better-auth/cli/dist/index.mjs:2172 return typeMap[type][databaseType]; ^...

not inserted into database prisma

i added additional fields but it doesnt seems to saved in db

Any NestJS GraphQL integration

I'm setting up my auth service using better-auth and was wondering if there's anything prebuilt for graphql, like the @thallesp/nestjs-better-auth dep for nestjs.

How secure is authClient.sso.register?

I saw this code snippet on the Better Auth documentation for register the SSO of a tenant: ```ts await authClient.sso.register({ providerId: "example-provider",...

google signIn roles

am i using 'scopes' right? it's not behaving as i'd expect... ``` const result = await signIn.social({ provider: "google",...
No description

Unable to set role during signup

"I'm struggling to consistently set user roles during signup with Better Auth, despite trying various hooks and configurations. The adminPlugin and Prisma schema seem to override my intended role assignments. What is the definitive approach to ensure roles are correctly set during signup, considering the interactions between plugins and database defaults?" The only way is to create user with "user" role and hope admin can update it. This is very limiting for a B2B commerce platform. databaseHooks and hooks do not work...

How to use CLI with Nuxt? (cant use useRuntimeConfig and other composables normally)

I'm trying to make better auth work like so - pglite for dev, postgres for production. I'm using drizzle and nuxt 4. So because better auth CLI is not in the context of nuxt I can't generate schema because of useRuntimeConfig

can we have callbackURL with emailOTP or passkey login?

i see callbackURL when using passwords but i am wondering if callbackURL can work in passwordless login scenarios?

Invalid drizzle schema for `defaultValue` of additionalField with type `string[]`

Below is how my src/auth/auth.ts tooks ```ts export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", // or "mysql", "sqlite"...
Solution:
nevermind

Magic Links vs EmailOTP?

I don't understand the difference between those 2 auth methods. isn't the same?

how to perform extra verification before allow user creation

i want to block disposable emails from signups. can i add pre-signup logic or disable client based signup api?

Better-auth ratelimit vs upstash rate limit

I am wondering if there is any meaningful difference in using https://upstash.com/docs/redis/sdks/ratelimit-ts/gettingstarted vs using better-auth rate limiting with redis as a backend (using redis.get() and redis.set()). I know that the upstash lib will use an efficient windowing algorithm. I could use the upstash middleware "upstream" from the better auth route handlers but I am not sure how supported that is....