Better Auth

BA

Better Auth

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

Join

bug-reports

help

better-auth-ui

hey how can i send additional data like some id with the sign up request without showing on the ui @daveycodez

twofa schema is missing

SERVER_ERROR: [Error [BetterAuthError]: [# Drizzle Adapter]: The model "twoFactor" was not found in the schema object. Please pass the schema directly to the adapter options.] { cause: undefined } POST /api/auth/two-factor/enable 500 in 987ms...
Solution:
had to export it

BetterAuthOptions database.casing?

Could someone please advise on what the casing option in BetterAuthOptions does? It is referenced in the docs here: https://www.better-auth.com/docs/reference/options#database ...

auth.api.getSession() Causing Issue on Vercel Build

i am trying to fetch the user session on the server to do some stuff with it and it works fine when running in locally, but when i build it on Vercel edge function and deploy it, it gives me a server error saying I'm calling localhost? I assumed maybe its the env variable so i logged it in build time and it is the correct domain what could the issue be?...
No description

Verify TOTP before resetPassword

I use SvelteKit and have applied BetterAuth's API calls server-side. I'm using a SvelteCookie plugin to ensure these are passed to the client. I want to solve for this use case: User signs up, verifies their email and sets up 2FA TOTP. Later, they want to reset their password. How do I ensure their TOTP is checked before they can trigger requestPasswordReset? ...

Cookie do not return on server (Hono)

Hi everyone, I've been working on an experimental project that combines React Router v7 (using framework mode) with Better Auth. For the backend, I'm using Hono along with the react-router-hono-server package. The login flow works fine, and I can successfully retrieve the user's session on a protected page via React Router. However, when I try to access the session inside a Hono middleware, it’s not available. Am I missing something in the setup or configuration? For context, here are the headers returned from the React Router loader compared to those in the Hono middleware:...

how can i prevent discord auth to automatically create new accounts?

basically i want the user to be able to sign in with discord only after he linked his discord account
Solution:
haven't tried it but seems like you just set it to false and it does what you want

Reusing Emails (soft delete feat)

hello everybody, I’m working on a project using BetterAuth and I have a question about handling soft-deleted users. In my setup, I have a users module and I’m creating users using the auth.api.signup method (with email/password). I’ve also implemented soft deletion by just toggling a boolean field — if deleted = true, the user is considered deleted. ...
Solution:
Yes it's still considered taken as Better-auth doesn't know that you have a soft-delete feature. We plan to support soft-delete in the future. In the mean time, I recommend modifying the existing soft-deleted user's email to have a suffix/prefix of some sort so that the email slot opens up for other users to sign up with....

I am new, can I use better-auth with rust backend?

My backend is in rust, I looked at the better-auth I loved it but they have only js implementation for backend. Is there any rust backend version or can I use client side only auth (I don't know how the db communicates without getting compromised). My frontend is React...

cookiePrefix fucks up nextjs middleware

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

discord connection + auth

how can i let the user connect his discord account and then on sign in page i want to have a sign in option with discord but only if the user connected his discord?...
Solution:
const accounts = await authClient.listAccounts();

const hasDiscord = accounts.data?.find((account) => account.provider === "discord");
const accounts = await authClient.listAccounts();

const hasDiscord = accounts.data?.find((account) => account.provider === "discord");
...

Link magiclink user to email account

When calling auth.api.signInMagicLink a new user will be created, if no user is associated with the used email, but this does not create an account. Is there a way to link this with the email provider? Running auth.api.SignUpEmail does not work, since the user already exists....

Handling OAuth sign-ins, signing up later

Hey y'all, what is the best/idiomatic way to sign a user in through Google OAuth, quickly verify if they're on a whitelist for example, and either redirect (not creating a user) if not, or proceed with signup? Getting signup_disabled when using disableImplicitSignUp

Need help for my Next.js Frontend + Hono Backend

I am implementing a Next.js frontend and a Hono BetterAuth backend server. In my Next.js frontend, I will use the authClient.signIn.email() function in client component. However, after the signin request is made, the authClient does not automatically store the session data. What is the appropriate implementation for this stack?...
Solution:
Yes. But it has been solved by configuring the CORS domain properly in Hono. Thanks!

Custom plugin not found type from ReturnType<typeof superAdminTableDataPlugin>

Hi everyone, I dont know why the Return Type of superAdminTableDataPlugin cannot get the type. Please somebody help me clear this . ``` export const superAdminTableDataPlugin = () => { return { id: 'super-admin-table-data',...
Solution:
This topic was closed because return type cannot get handler and endpoint in server custom plugin function.
No description

How do you send an authenticated request?

I'm either blind or confused, from the docs I can't find anything on how to send a request to a backend (ExpressJS) in this case for a simple protected route. I can login/logout, but if I attached the token in a header "Authorization" : Bearer ${token} and my middleware looks like the following ...

to set a cookie does not work

```ts import type { BetterAuthPlugin } from 'better-auth'; import { createAuthEndpoint } from 'better-auth/api'; import { z } from 'zod'; ...

Github cancel UI

If a user decides the cancel on github, they see a better auth UI - is there anyway to override that?

accessing plugins in DB hooks

Just a question if it's possible or not to access plugins in the DB hooks. good example is creating an organisation when a user signs up? looked around the docs and couldn't find much...
Solution:

Caching a user session with multiple relations (drizzle-orm postgresql)

Hello, I was wondering what would be the best way to handle this problem. I have a user schema and relations made in drizzle like this: ``` export const user = createTable("user", { createdAt: timestamp("created_at", { withTimezone: true })...