Better Auth

BA

Better Auth

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

Join

bug-reports

help

Invalidate useSession()?

I'm using authClient.updateUser() to update user's name, but I want to make sure the new name is reflected in the useSession return value before performing a url change. Any way to make sure of that? Anything like Tanstack Query's .invalidateQueries()? I see there's refetch() on useSession() but it doesn't return a promise for me to make sure the refetch is completed....

Better Auth Microsoft OAuth - email_not_found Error

Hi team! I'm having an issue with Better Auth and Microsoft OAuth integration. When trying to authenticate with Microsoft, I'm getting this error: "Better Auth Error: We encountered an issue while processing your request. Error Code: email_not_found" ...
No description

Help with Stripe payments

Hi I have a problem with Stripe. I have test mode on, and when completing a payment with the test card (4242), payment is successful but on my DB looks like "incomplete" instead of "trialing", does anyone know why? This is my code implementation: async function handlePlanClick(planId: string) { try {...
No description

Any way to get cookies from client signIn methods when used as server action?

Any example ```js "use server"; import { signIn } from "@/src/lib/auth-client";...

`getSession()` coming back as null in Hono/ORPC middleware

Has anyone used ORPC with Better-Auth? I am trying to do so but sessions are coming back empty. Under the hood it uses Hono: ```ts const app = new Hono(); ...
No description

State check failing for Discord OAUTH2

First time using Better Auth with MongoDB. Here's my sign in function: ```ts const signIn = async () => { const data = await authClient.signIn.social({ provider: "discord",...
No description

Email sign-in takes a long time to execute

Hey good people! I've been working on a better-auth project with hono as a backend server hosted on cloudflare workers (with drizzle + d1 as my db) I've noticed that sign-in requests consistently take almost 5 seconds to execute, and I was wondering if this is to be expected due to using drizzle, and if it's not, how could I try to debug this? Thanks for any shared tips! Project is open source if you want to check the whole thing, but my auth config file looks like this:...
No description

The delete user operation failed silently without throwing any error message.

I'm trying to delete users from the system. The issue is that they have relationships in the database. Initially, when I was working on the backend, they weren't being deleted properly. Today I realized I needed to handle their deletion by implementing a pre-delete hook in the Better Auth configuration. So you have any idea how to have proper error handling, so I could have better development experience. The current user deletion code works, but I think it's problematic to have to consider maintenance timing, as it's a potential issue waiting to happen. ```js export const auth = betterAuth({ plugins: [expo()],...

Disabling email scope on Github oath

Hey! I'm currently trying to use better-auth with drizzle. I want to use Github's oath to sign the users in, though I don't want to access their emails. I've tried adding scopes like read_user, read:user, profile or similar to the scopes yet nothing really works. They all still require emails to be read. Is there any way to add a scope that does this? Has this been added to better-auth yet? Doc link
Solution:
Got a fix: ```ts github: { // ... disableDefaultScope: true,...

session cookie not setting after signup

Hey folks here is the link to my current auth setup https://mystb.in/5609e26466b88cb244 I don't know why after I signup the session cookie is not setting session is creating in database

Need Help with Multi-Tenant, 2FA, and Role-Based Authentication in NestJS using BetterAuth

Hi everyone, I’m currently working on an SSO using NestJS as the backend framework, and I’m running into a few challenges related to authentication and authorization with BetterAuth. I hope someone in the community can point me in the right direction or share their experiences. Here's what I'm trying to achieve:...

Can I Add a User-Type Condition to the SQL WHERE Clause During Sign-in?

I have added a "role" field to the user model as follows. Is it possible to add a condition to the SQL WHERE clause to only include users with a specific "role" when signing in? I have looked through the documentation and source code, but I couldn't find a way to extend the SELECT conditions. Please let me know if there is a good way to do this....

CSRF with Next.js server directive w/ Backend Api

For CSRF to work (with Next.js server directive), so that the client requests get forwarded from the Next.js server to our BetterAuth backend API, do we need to manually forward all of the headers to the backend API?

Vite cannot find "react" import in the npm package

I'm implementing the svelte demo in my sveltekit app as a test, and when running vite server, this error occurs: ``` ✘ [ERROR] Could not resolve "react" node_modules/better-auth/dist/client/react/index.mjs:3:58:...
Solution:
Solved: The initial import of the library in the client was using "better-auth/react", needed to change it to "better-auth/svelte" to import the correct framework library.

Exclude role in the signup (frontend) as it should be driven from the backend

Hey Guys, I added the field role So i added this in React: export const authClient = createAuthClient({ plugins: [inferAdditionalFields({ user: { role: { type: "string" } } })], ...

oidc provider - Change issuer?

Is it possible to change the issuer at the oidc provider ? It defaults to the apps domain...

Update TypeScript types of the user ID table

Hello, I looked at different posts here and I understand that the ID from the user table can't be changed but I've modified my SQLite database schema to use an integer type for the primary id column of the user table (because I did a migration and I need to keep the IDs). ...

redirect after sign up, emailAndPassword

``` await signIn.email( { email, password, callbackURL: "/admin",...