Better Auth

BA

Better Auth

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

Join

bug-reports

help

failed to Failed to create user Error [PrismaClientValidationError]

Here's a condensed version under 2000 characters: --- πŸ› Better Auth SignUp Error - Password Missing Despite Existing in Schema...

Certain endpoints not working

After days of struggling I finally got a copy of BetterAuth to work with a fresh copy of Elysia and Prisma. Then I moved on to port an old project from Lucia to BetterAuth, signing in and signing up is working, same goes for creating a new organization, but listing organizations as well as any of the other BetterAuth endpoints shown in swagger all return a 404 not found, as in route does not exist. How can some routes work and others not....

B2b saas multi-tenant organization with turso

Hi guys, I try to make a multi-tenant b2b saas using turso and better-auth. I need a help how to design my relationships using better-auth organization plugins. Whats its the correct approach to manage this?

Managing Shared Drizzle Schemas in a Multi-Repo Next.js Setup

What's the best strategy to share Drizzle + BetterAuth schema definitions and related authentication code across four separate Next.js repositories, given that the auth code resides in one 'portal' repo and each of the three 'product' repos requires access to the user session & user fields, ideally minimizing redundant schema updates? (all are on the same domain with different subdomains)...

How do you show ban reason and expiry on a banned page?

Hey everyone, quick question! I'm using Better-Auth with Next.js, and I have a before hook that redirects banned users to a /banned page: `hooks: {...

Getting 401 error in console

```js const users = await authClient.admin.listUsers({ query: { limit: 10, },...

Middleware is not working in Next js v15.4.0

```js import { NextRequest, NextResponse } from "next/server"; import { getSessionCookie } from "better-auth/cookies"; export async function middleware(request: NextRequest) {...

Cloudflare D1 with kysely binding not available during build time

I'm using Kysely to integrate Cloudflare D1 database into my nextjs app. The binding is not working in build time since it need the cloudflareContext env that is not available if the server is not running. In preview it simply fails to make the query, since the db variable is undefined. I've been reading documentations for days and i've tried a lot of solutions. I choose cloudflare D1 because it is supposed to be easy ... I always used this database for my data storage solutions and I never had any issue before using BetterAuth . Also, if I try to create the database migrations with the cli (npx @better-auth/cli generate) it simply fails saying i need to call initOpenNextCloudflareForDev() in my next.config.ts but the function is there! Can someone show me how to configure and export correctly the database instance ?...

Stripe plugin: subscription still incomplete in database

I setup better auth stripe plugin but on successful payment and receiving the webhook the subscription entry in the database keeps having the status incomplete and not updating subscriptionId and startDate. I am using referenceId if the organization (id)....

Additional fields - how to do object? (Mongo)

I want these nested under the emailNotifications. This would be simple JSON in Mongo, not sure how to do it here. ``` emailNotifications: {...

What is the difference between the Generic OAuth, SSO, and OIDC Provider plugins

Is the following correct? - Generic OAuth: Allows users to sign in with a preconfigured OAuth2/OIDC - SSO: Allows users to dynaically register their own OIDC in order to sign in - OIDC Provider: Allow BetterAuth to act as an OIDC provider...

can't list users as an admin

```ts import { createAccessControl } from "better-auth/plugins/access"; export const statement = { project: ["user", "premium", "admin"],...

how can i migrate user accounts from nextauth (mongo with prisma) to better auth (drizzle + pgsql)

so it should be pretty straight forward, but about the userid and accountid can i generate that to be random?...
Solution:
Yeah those can be random, if you really want it to match what Better-auth would generate out of the box you can use our function:
import { generateId } from "better-auth";
import { generateId } from "better-auth";
...

Cypress E2E Social Sign-In Session

Seeking some help mocking a session within Cypress E2E Next.js project: Using Google sign-in: I started off trying to mock the /callback endpoint providing the code from Google OAuth Playground based on this Cypress guide, but got stuck with mocking state because i'm not sure where or how in the source code its being set. ...
Solution:
I found the way, basically dont e2e oauth. I use email+password for dev only to gain session

Nextjs API auth.api.getSession session.user.role undefined

I try to get the user Role from session , it become undefined. DB already have a admin account with role = admin. ```...
Solution:
can u try to put nextCookies plugin to the bottom

Restrict Login/SignUp

I want to build an app where only authorized users have access, and I only want to support github auth. How to create a plugin which checks if the email is whitelisted?

how to create a row in a diff table upon user registration

upon user sign up how can i create an extra row in a table with user's id?

Getting too many failed query errors on workers

I had a pretty weird question, I am using better auth on my hono backend with the drizzle adapter Everything works fine while I am running things on a local host but when I deploy it to cloudflare workers I start getting a lot of failed queries. ...

Using stripe with a diferent backend

Hey guys, I'm using the Stripe plugin, but the successUrl and cancelUrl are redirecting to my backend instead of my frontend. How can I change that behavior? I'm using fastify with prisma and nextjs...

sign up hook

on user sign up i need to generate him a key pair and encode the private key with his password, then save it to the user table in database, how can i do it in better auth?