Better Auth

BA

Better Auth

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

Join

bug-reports

help

error thrown in better auth plugin is not captured by better-auth configured logger

I’m trying to use Better Auth in a Fastify application Below is the part of my configuration: const betterAuthOptions: BetterAuthOptions = {...

refresh useSession()? Impersonating isn't updating the session.

I call: await authClient.admin.impersonateUser({ userId: id })...

useSession doesn't get session in TanStack Start

I have a TanStack Start SPA web app connected to a separate backend. I have enabled: ```ts export const auth = betterAuth({...
Solution:
Make sure to pass headers into the getSession call.

Internal Server Error

"use server"; import { auth, ErrorCode } from "@/lib/auth"; import { headers } from "next/headers"; import { APIError } from "better-auth/api";...

Using OAuth2 but not for signIn

Hi, I'm working on a nextjs project for my company and I need to set up an oauth2 connection with one of our partners (who isn't one of the better-auth default social providers). My problem is that I don't want to use oauth to connect the user but only to be able to use the token to access my partner's api. Do you recommend that I use better-auth (and if so, how can I get custom behaviour (especially for receiving tokens that I need to store in a specific place)?...

Does this code have any flaws in terms of Better Auth best practices?

```ts export const updateUserSF = actionClient.metadata({ permissions: { user: ["set-role"] } }) .inputSchema(z.strictObject({ id: z.string(), personId: z.int().optional(),...

Proxy OAuth2 on Vercel

Hey ! I need to proxy the initial OAuth2 request that goes to the server via a socks5 proxy, what is the best way to do that, this is the request I want to proxy over to my socks5 : POST /api/auth/sign-in/oauth2...

Cross-Organization Teams Support in BetterAuth?

Hi! Quick question about Teams. In our case, we have financial partners (internal users) who manage multiple client organizations. Ideally, we would like to create one or more Teams that are shared across multiple organizations — so that these users can easily work across clients without having to be added individually as members to every organization or having to copy across a team for every organization. Is this something that Better Auth currently supports (or plans to support)?...

Bypass Email Verification

Hi, Is it possible to conditionally disable the emailVerification feature during signup ? (I.e. put at signup the emailverified == true and not sending verification email with token) ...

Issue with monorepo setups

It doesn't seem possible to use a default config and export to multiple apps while maintaining type inference (i.e. loses additional fields etc.). Is there something I'm doing wrong or is it just not implemented to work like that? Also, if I try to return without explicitly setting the return value as "BetterAuthOptions" it gives this error: The inferred type of 'getAuthDefaults' cannot be named without a reference to '../nodemodules/better-auth/dist/shared/better-auth.Bzjh9zg'. This is likely not portable. A type annotation is necessary.ts(2742)...

Why do when I log in with facebook the emailVerified is false but I still get logged in?

When I log in with facebook my emailVerified field is false but I still get logged in. Isn't it supposed to work like it is in email and password?

I have session, but get unautherized error from auth.api.polar or something similar

``` export const validateApiKey = async (c: Context, next: () => Promise<void>) => { const apiKey = c.req.header("x-api-key"); const session = await auth.api.getSession({ headers: c.req.raw.headers }); ...
Solution:
fixed it ``` const meters = await auth.api.meters({ query: {...

api key validation problem

When I search for api key using the DB, it appears, but doesn't work when I try the same using api key validate, I get an error Keys not found I am using this in external api, which dont have auth setup thouhg, coz my main app is nextjs, and for hono I am using api keys so people can call endpoints...
Solution:
you dont have the key hashing disabled, the keys table with the key column is a hashed version, it will not be the actual key, usally the key is provided to you when you create the key use the value instead.

How can i use User collection with Mongoose?

Im using user id from users collection another posts collection and created by key is saving user collections Id While fetching posts i want to populate user also using the id But its not getting ...

user onboarding

Hi, what do you think is the best way to make user onboarding mandatory? I'd like users to fill out their username before they can start using the app.

Property 'organization' does not exist using mongodb adapter

I'm having an issue with organization plugin using mongodb adapter. organization not working with authClient or auth on server side....
No description

Discord OAuth Issue

I'm recreating this post but with much less rambling than our old post to make it more digestible. (https://discord.com/channels/1288403910284935179/1383602900923842660) We have a huge bug with BA. Every time a user OAuths (a) using ONLY Discord and (b) ONLY on prod, a brand new account/user is generated. This does NOT happen locally, or with email/pass/other oauth providers. X...

Duplicate Stripe customer

Hello! I'm using the Stripe plugin with Drizzle and Astro, everything works fine except that the Stripe customer is created twice: - One customer gets created when on sign up - One customer gets created when calling the subscription.update function to redirect to Stripe for the payment Did anybody experience the same problem? Thanks in advance...

Oauth provider not working

I have a oauth provider that supports PKCE with implicit grant but it errors with Error Code: oauth_code_verification_failed Looking at the documentation they specify this on PKCE, REQUIRED. A minimum length of 43 characters and a maximum length of 128 characters. See the detail of PKCE code_challenge....

Admin not authorized

I am trying to list users with the admin plugin but even when my users only role is "admin" I get a 401 from the endpoint. What could I be missing?
Solution:
I fixed it. I had the role imported as a different name because the plugin is named admin. I renamed the plugin import and it started working.