Better Auth

BA

Better Auth

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

Join

bug-reports

help

How do I validate sessions / access in my backend

Am I correct to assume that I need to query the db based off the access token provided to verify if the request is legit, or is there an api that I can use to do this built-in to better-auth? My backend api is made in C# using ASP.NET core, so I need to protect certain routes which is why im asking....

svelte-kit-example not working

I followed the instructions, but I had to move the whole example outside of the workspace to install the dependencies and then i had to install better-auth from npm rather than the workspace (obvs). But then it won't run still "Button" is not defined. Confused ......

Property 'oauth2' does not exist on type

Code runs as expected, type just doesn't exist? Next 15.3.0 with 1.2.7...
Solution:
you need to add generic oauth client plugin
No description

Side effect on session changes

Hi, what's the safest way of perfoming a side effect after the user logs out, logs in... when the session changes. Something like that? ```typescript...

What are the differences between User vs Account?

I'm integrating Better Auth into my SaaS for authentication, but these 2 terms make me confused. Is User the actual user in my system (registered via my authentication mechanism) and Account is similar to Customer in other payment platform (the link between my system and the payment platform) ?

Making Auth with 2 tables with different auth flows

How can I achieve to make better-auth work with students and teachers both are users essentially but with different plugins/login methods. teachers login with magic link while students can use oauth (google, facebook etc),passkey?...

Admin Plugin - Issue with cookie cache and secondary storage not updating on `auth.api.setRole` call

I'm encountering a problem with cookie cache and secondary storage behavior when updating user roles using auth.api.setRole in my Remix+Better-Auth project. Issue description: - When I call auth.api.setRole to update a user's role (e.g., promote a user to "admin" or revert them), the response headers do not include any Set-Cookie headers. Example response headers look like this:...

How to manually create a session and a cookie with proprietary SSO?

I’m working with a big enterprise platform that has a proprietary single sign-on (SSO) process. This platform will post an encrypted payload to an endpoint on my server. I have been given a key to decrypt this payload, and inside this payload is all of the user information like email, name, etc. Simplified, I receive a trusted POST message to an endpoint with a user's email. How can I check to see if this user exists, manually create a session for this user, and then redirect them back to a URL after this happens?...

mapProfileToUser doesnt work

I have a problem: mapProfileToUser doesn’t work when I want to grab and save my user’s Discord ID as identifier in the session. When I print the profile, it contains the id (which is the Discord ID) property. However, when I print my session user, there is no identifier property. auth.ts...

Twitter OAuth not returning email despite proper configuration

I'm using better-auth with Twitter OAuth and can't get the email address from users. I've set up everything according to docs but still getting:
ERROR [Better Auth]: Provider did not return email. This could be due to misconfiguration in the provider settings.
ERROR [Better Auth]: Provider did not return email. This could be due to misconfiguration in the provider settings.
...

Pending State not getting resolved

I'm trying to use the traditional signup method. But, it is in a pending state forever and not getting resolved. The login method is working. At least, it is immediately returning something. I'm using Next.js for the frontend and Express.js with the backend and drizzle pg for an ORM....
No description

Use Middleware to onboard users into organization

Hi everyone! I'm building an app which makes it mandatory for a user to be in an organization since it is B2B. My initial thought was to write a middleware function that checks whether a user is affiliated with an organization (which a new user wouldn't be) and redirect them to an onboarding page (which is whitelisted from the middleware to avoid infinite loops) which will allow them to either create or join an existing organization (using an invite code, probably). I'm currently using NextJS v15.3.1 with this method for getting the session inside my middleware, but the auth instance can't run since it is server side, and I can't use the authClient since that is meant for react components and doesn't work inside my middleware...

Betterauth is Slow?

import { products, favorites } from "@/db/schema"; import { useDrizzle } from "~/server/utils/drizzle"; import { and, count, eq, sql } from "drizzle-orm"; import { auth } from "~/server/utils/auth"; ...

Prisma 6.7.0 error with better-auth

I upgrade to Prisma 6.7.0 and use the new rustless feature, but I keep getting this error now with better-auth. Any ideas? ``file:///Users/salvatorenoto/Developer/Apps/rent-tracker/node_modules/@prisma/client/runtime/client.mjs: Invalid source map. Only conformant source maps can be used to find the original code. Cause: TypeError [ERR_INVALID_ARG_TYPE]: The "payload" argument must be of type object. Received null 2025-05-01T03:33:00.606Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [Error [PrismaClientKnownRequestError]: Invalid db[model].findFirst()` invocation in...

Stripe create user with trial subscription without requiring credit card?

Is it possible to create a user and instantly assign them a subscription with a trial period without requiring credit card details upfront? The idea is that the user can use the product during the test phase and is only asked to enter payment information after the test phase has expired if they wish to continue....

Create new roles and permissions client side

Hello, my app is based on user roles and permissions. I want to create a page where the admin user can create and manage new roles and assign permissions. However, better auth does not have a role and permission tables. Is it possible to do what I have in mind?...

Use setSessionCookie outside plugins

Hello, I have an endpoint in nuxt, I sould use setSessionCookie, but I'm not unable to recreate the context ``` const auth = await serverAuth()...

useSession query behaviour?

I have a couple of extra fields on my user table that I like to have when I call useSession, but currently it seems to only include the base "id", "name", "email", "emailVerified", "image" however when I turn the logger on in drizzle it seems like when get-session endpoint get's called it actually queries all the data from the table. I guess my question is, since the data is already queried how can i pass it so it's available in my useSession hook....
No description

Help Understanding Better-auth

Using Nextjs Ive just started messing around with better auth to understand the fundamentals of how it works. My question is around if auth and authClient are designed to be used interchangeably. ...

set-auth-jwt header not always set

Hi, When trying to implement the jwt token in sveltekit/hono combo, the set-auth-jwt is not always sent with the session as you can see in the following screenshots from the auth/get-session endpoint. Is it something expected from better-auth or an issue on hono side ? note: even custom-headers set in hono middleware seem to be striped from auth endpoint...
No description