Better Auth

BA

Better Auth

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

Join

bug-reports

help

Does forwarding a JWT from a React SPA to C# .NET app make sense ?

I understand Better Auth is for TS codebases and it looks great. I want to keep my users managment in my db 🙂 I know nothing about C# .Net but I've been asked to build with 3 specific goals... 1) create a React SPA which handles the UI for users, profiles, payment, chat, etc...

Is there a way to get the refresh token after using a social provider?

I didn't find it in the docs but I was wondering if it was possible to get the refresh token from google after sign up. I need it for a calendar integration that I am building. If not is there a way I can handle the oauth2 callback myself so I can get it?
Solution:
pass accessType: "offline" in your google config

How can I get member with user in adapter

I'm trying to create a plugin that needs the listing of organization members. So I want it to get members and also users. ```ts listMembers: async (organizationId: string): Promise<Member[]> => { const members: Member[] = await adapter.findMany({ model: "member",...
Solution:
You can't using the current implementation of our adapter system. You'll need to use the adapter and fetch each user by user ID as well....
No description

guys, is it possible to do with better-aauth??

Guys, do you know if it's possible for me to do this? On the front end, log in with discord, any other provider, after logging in, send a request to the backend to set the user in the database, however, I wanted to send the jwt (I don't know if this is used in the cookie) to check whether or not the user is in the database after front-end signin --> back-end request to set the user to db, (do not set by front end)...

Error generating schema

So whenever I try to generate my schema (Using prisma)
npx @better-auth/cli@latest generate
npx @better-auth/cli@latest generate
I get the error in the image. I tried to generate the schema on a lot of my better-auth projects but in vain....
No description

How can I get other plugin's option in my plugin?

I'm building a plugin to extend organization plugin. I want to get organizationOptions so I can handle other stuff in the plugin. How can I achieve that? I tried
ctx.context.options.plugins?.find((plugin) => plugin.id === "organization")?.options
ctx.context.options.plugins?.find((plugin) => plugin.id === "organization")?.options
but that didn't work even though organization plugin is setup correctly......

cross-site cookie in express

I see past issues with cross domain cookies am not sure if a resolution was reached i've resorterd to disabing secure cookies to work around this ```ts advanced: {...

cookieCache doesn't work with customSession plugin

Hello. I'm wokring on a next.js 15.3 application and noticed that cookieCache doesn't work once I add customSession plugin. I enabled query logging for Prisma client, and see that it queries database on every getSession() call. Maybe I'm missing something obvious. Did anyone have similar issues? Here is my config: ```ts export const auth = betterAuth({ database: prismaAdapter(db, {...

redirect after signout on a protected page

In Next.js, how do we redirect the user if they sign out while on a protected page? middleware below only gets executed on initial load ```ts import { NextRequest, NextResponse } from "next/server";...

Hono on Cloudflare Workers with Better Auth always returning 401 Unauthorized

Using the better auth handler in the restricted endpoints like list sessions. It always returns unauthorized even after sign in with email. I'm using Scalar docs to test the api. The cookie is being set I've checked by logging it. But still it's returning unauthorized. ``` //auth.ts...
Solution:
Fixed it by transforming the headers when passing to the routes ``` export const getHeaders = (headers: Headers) => { const newHeaders = Object.fromEntries(headers as any) const headerObject: Record<string, any> = {}...

NextJS Build Fail with createAuthClient

My nextjs build is failing when calling createAuthClient from within Middleware. When I remove it, error is gone. ```import { createAuthClient } from "better-auth/client"; import { NextRequest, NextResponse } from "next/server"; ...
Solution:
ok solved
No description

Trouble creating session after login with 2fa enabled

Hi, I'm using Better-Auth with the Prisma adapter in a Next.js (App Router) project, and I’m having trouble with session creation when a user has 2FA enabled. When logging in with correct credentials using authClient.signIn.email(...) from the client, the server responds with 200, but: No session is created in the database (checked directly via Prisma)...

How to save custom fields (like address) in my database when admin creates a User?

I’m using the admin Plugin to create users. When an admin create a user, I need to save address data in my own database table (Address model). i tried to add the address field the data ```ts const { error } = await admin.createUser({...

Output debug mode?

Is there any way to output more debugging stuff? I'm getting an error which is quite difficult to debug;
error PostgresError: column "undefined" does not exist
error PostgresError: column "undefined" does not exist
...

Can better-auth/client be used with a non-Node backend (e.g. Symfony)?

Hi! 👋 I'm building a Nuxt frontend and I'm interested in using better-auth/client to handle authentication. However, my backend is an external service built with Symfony (PHP), not Node. Is there a recommended way to integrate better-auth/client with a non-Node backend like Symfony?...

Error: Too many connections (MySQL)

I currently use better-auth in combination with a MySQL database. I use NextJS to render my website. I noticed that when making repeated changes (re-renders) better-auth throws an error:
Error: Too many connections
Error: Too many connections
. I have looked through previous posts and found that someone had the same issue when using a Prisma client. Given that I do not initialize the connection to the database myself, I was wondering how to store the connection during development? This is what my configuration looks like: ```ts export const auth = betterAuth({...

oauth redirect to homepage on another domain

Hey guys thank you so much ofr this awesome project but i just had a question On successfull oath login ammgetting redirected to local:host:5000 (my expess api) instaed of localhost:3000 (my frontend How do i change this behavior...

Redirect Problem

hello again, I am struggling with another interesting problem. I am using Next 15.3.0 and my middleware.ts file is as follows ...

Setting Admin Roll With Hook

```ts hooks: { before: createAuthMiddleware(async (ctx) => { if (ctx.path === "/sign-up/email") { const email = ctx.body.email.trim().toLowerCase();...

Trouble Creating Session After Login with 2FA Enabled – No Session Created or Persisted

Hi, I'm using Better-Auth with the Prisma adapter in a Next.js (App Router) project, and I’m having trouble with session creation when a user has 2FA enabled. When logging in with correct credentials using authClient.signIn.email(...) from the client, the server responds with 200, but: No session is created in the database (checked directly via Prisma)...