Better Auth

BA

Better Auth

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

Join

bug-reports

help

Plugin Development Starter codebase

Hi i am a newb developer ..but better-auth is a great inspiration developer like to learn and code A Humble request if there is any starter code base to develop better-auth plugin with the test setup
It will be really helpfull to have something like that to start creating plugins...

How to change @id default format with prisma

Hello guys model User { id String @id @default(dbgenerated("concat('usr_', (nextval('user_seq'::regclass))::text)")) ...other fields...

How can I handle the Apple review process when using the phone number plugin ?

For Apple review, I need to create a test account for the reviewer to log in. The login process is as follows: 1/ Enter their phone number 2/ Enter the OTP received by SMS However, the reviewer can’t use a real phone, so the account must be created in advance, and the OTP must always be the same....

Custom plugin Type Error

How do I infer the types for the endpoints to my custom plugin? I'm getting the following type error when calling a custom plugin endpoint. It works, but TypeScript doesn't know the function exists: ```...
No description

Sign-up: posting fields to other tables

I've added additional fields to 'user' that all post fine, but I also have another table that takes the user.id as a foreign key and one field that authClient.signUp.email sends belongs to this table. I'm using a Drizzle Schema for the db, so the schema is at least known by BA. ` database: drizzleAdapter(db, { provider: 'pg', schema: dbschema, // contains all tables ...
Solution:
I recommend just creating a row in that other table in a database hook

Is it safe to check the user session only in middleware and not in routes in Hono?

This is not recommended in Fullstack frameworks like SvelteKit and Nextjs. But with Hono, can we rely on this? I mean checking the session in a global middleware, and just returning 401 there if cannot get it... I believe yes, but I just want to double check, and also maybe some experienced person can update the documentation 🙂...

Do

does better auth store cookies in secure store when you set it up with secure store because everytime i am always making a request to my backend for the cookie

Stripe typescript error

Type '{ id: "stripe"; endpoints: { stripeWebhook: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "POST" | undefined; } & { query?: Record<string, any> | undefined; } & ... 4 more ... & { ...; }) | undefined): Promise<...>; options: { ...; } & ...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'init' are incompatible.
Type '(ctx: AuthContext) => { options: { databaseHooks: { user: { create: { after(user: { id: string; email: string; emailVerified: boolean; name: string; createdAt: Date; updatedAt: Date; image?: string | ... 1 more ... | undefined; }, ctx: GenericEndpointContext | undefined): Promise<...>; }; }; }; }; }' is not assignable to type '(ctx: AuthContext) => void | { context?: { appName?: string | undefined; baseURL?: string | undefined; secret?: string | undefined; secondaryStorage?: { get?: ((key: string) => string | ... 1 more ... | null) | undefined; set?: ((key: string, value: string, ttl?: number | undefined) => void | Promise<...>) | undefin...'
Type '{ id: "stripe"; endpoints: { stripeWebhook: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "POST" | undefined; } & { query?: Record<string, any> | undefined; } & ... 4 more ... & { ...; }) | undefined): Promise<...>; options: { ...; } & ...' is not assignable to type 'BetterAuthPlugin'.
Types of property 'init' are incompatible.
Type '(ctx: AuthContext) => { options: { databaseHooks: { user: { create: { after(user: { id: string; email: string; emailVerified: boolean; name: string; createdAt: Date; updatedAt: Date; image?: string | ... 1 more ... | undefined; }, ctx: GenericEndpointContext | undefined): Promise<...>; }; }; }; }; }' is not assignable to type '(ctx: AuthContext) => void | { context?: { appName?: string | undefined; baseURL?: string | undefined; secret?: string | undefined; secondaryStorage?: { get?: ((key: string) => string | ... 1 more ... | null) | undefined; set?: ((key: string, value: string, ttl?: number | undefined) => void | Promise<...>) | undefin...'
...
No description

OAuth allow sign up based on token property

Hey! I want to only allow users to sign up that have a certain property on their id token/provider profile. Specifically I want to filter for the hd property on the Google profile. What's the best way to achieve this?...

User Choose his role on signup

Hello, i want to make the user choose his role on sign up but the sign up function does not allow to do that and when i use hooks to update the user. after hook is not working with social signin it works good with email but not social how to make it with social. ```js hooks: { after: createAuthMiddleware(async (ctx) => {...

Get magic link without sending an email

I need to extract the URL directly from the request on the backend, but I’m not sure if it’s even possible since the function doesn’t provide any URL or token parameters.
Solution:
Yeah your best bet is to use your ORM. It would be silly of us if we returned the link in the response of that endpoint

How can I make a "error middleware"?

Hi guys. So, I have the back-end config of better-auth and the front-end client. The thing is, I need to format the errors of the better auth to normalize them to the default error pattern that my back-end provides, and for such, I needed some kind of error middleware of the better auth in the back-end. I tried the following in the back-end config: ...
No description

Better Auth with without ORM, use Firestore, Hono

Hi there, can I use Better Auth SSO for my backend HonoJS with Firestore as database where storage users data. And frontend sites are Next.js (site A.domain.com) and Astro (b.domain.com). Is possible?

Integrating with SvelteKit

The following code works fine, ```ts // hooks.server.ts import { auth } from "$lib/auth"; import { redirect } from "@sveltejs/kit";...

Trouble with custom plugins

Hey guys, my English is not very good, but I'm having a problem with a custom plugin. I want to create one where each organization can have projects. The creation works fine, but when I try to use the GET methods, I can't use the hooks like this: const { data: allProjects } = authClient.useAllProjects();...

SvelteKit cookie get's nuked after being created

So I have a setup of sveltekit + elysia backend(separated services) created with t-better-auth.. locally everything works perfectly. but in production my login does not work at all, the cookie get's created (I can see through the chrome devtools), but then when the redirect to /dashboard happens, the cookie gets nuked and the hooks.server.ts is unnable to validate the session. This would make so that the only viable way of working with better-auth in sveltekit would be 100% client-side code, which is horrible for both DX and UX....
No description

Opening reset password link causes ` text and nvarchar are incompatible` error

Hello re-posting again with some better text: I am currently implementing password reset functionality. The problem I got stuck on is that when I open reset link (received in email) server throws this error SERVER_ERROR: [Error: The data types text and nvarchar are incompatible in the equal to operator.]...

The inferred type of 'authClient' cannot be named without a reference...

I was trying to create a shared auth client package in my monorepo, since I have multiple frontends authenticating with the same server.. But I keep getting an error like this (twice) even before adding any plugins... Literally.. this is my entire code: ``` import { createAuthClient } from "better-auth/client";...

Better-auth + neon + prisma

The error after clicking signup button (the minified code is so long so I left out unimportant part) `` 2025-07-31T13:14:19.733Z ERROR [Better Auth]: Failed to create user Error [PrismaClientValidationError]: Invalid prisma.user.create()` invocation: ...