Better Auth

BA

Better Auth

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

Join

bug-reports

help

Replace or override baseEndpoints

I want to replace the built in resetPassword endpoint ``` const authenticator = betterAuth({ plugins: [ {...

Change email for unverified user ?

Is there a way to change the email of a user that hasn't been verified ? For exemple this cover the case a user register miss type the email and want to change to his good one.

MSSQL not working at all

Hi, is anyone using BetterAuth with MSSQL via Kysely? Migrations run fine for me, I can see the tables getting created in the DB, there is only 1 other table in it. When trying to login, I get: SERVER_ERROR: The data types text and nvarchar are incompatible in the equal to operator. ...

activeOrganizationId is null, but user is in Org.

Hey, I tried to get the activeOrganizatuinId with ```typescript const session = await auth.api.getSession({ headers: await headers(),...
No description

Multiple roles per user in Admin plugin

Hello, I'm trying to create an app using NextJS. I'm using Better-Auth with the admin plugin which seems good enough for what I need. However, I want to be able to provide users with different roles, but having multiple roles, e.g. Accounts, Sales etc. Using just the Admin plugin, how can I assign multiple roles to a user. I don't really want to use the organisation plugin, as I don't need that complexity just for multiple roles. Thanks!...

fetchOptions hooks not running

I'm seeing the following: - request specific onRequest/onResponse/onError/onSuccess run correctly - authClient onResponse (for all requests) runs correctly - authClient onRequest only runs if there is no request specific onRequest...

Dealing with generic OAuth provider that does not send email and account linking

Two part question: Hi all, we have a external OIDC IdP that does not reliably return an email in the token claims. When using the generic Oauth plugin, we get a Error Code: email_is_missing on callback. mapProfileToUser does not seem to get around this error. What's the best approach here? Second, we do get a reliable universal user identifier in the claims that can link a user to a specific human. Is there a way to customize the account linking feature based on something other than email but instead this unique user key?...

API Keys on Organization level?

hey guys, am new to better auth and saw there are plugins for organizations and for API Keys. according to the docs, API Keys are user scoped, would need them on Organization and team level, is that possible? if not, would go ahead and file a feature request 😉

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