Better Auth

BA

Better Auth

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

Join

bug-reports

help

displayUsername is normalizing to lowercase.

Im not certain what has happened but recently my better-auth has been normalizing my displayUsername submitted to the better-auth library. On the network request it appears to be sending it to the API endpoint with the correct uppercase and lowercase letters but my database, neon.tech, is showing it in lowercase only. Has this been an issue for anyone else before? I can provide any code needed to fix this....

Extra Args for Hooks

Is it possible to extend the args for a builtin endpoint to have access to additional information in the hook? e.g. call signUp with an additional key "foo" and use "foo" in the after create user hook?

How to associate OAuth access tokens with application-specific context during OIDC flow?

I'm building a data sync platform where users can create multiple "destinations" (e.g., different Airtable bases, Notion workspaces) to send their data to. I want to use the OIDC plugin so that each OAuth access token is tied to a specific destination. Current setup: * Using better-auth's OIDC provider plugin * Have a destinations table that I want to link to oauthAccessToken via a new destinationId column...

Migration from SQL DB to PostgreSQL DB Password Verification Error

Trying to migrate users/accounts from my SQL DB (pre better-auth implementation) to a PostgreSQL DB (better-auth implementation). However, when hashing the passwords with Scrypt.NET and trying to login I get a
ts│# SERVER_ERROR: Error: hex string expected, got undefined^CTerminate batch job (Y/N)? Terminate batch job (Y/N)?
│ at hexToBytes (../src/utils.ts:164:37)
ts│# SERVER_ERROR: Error: hex string expected, got undefined^CTerminate batch job (Y/N)? Terminate batch job (Y/N)?
│ at hexToBytes (../src/utils.ts:164:37)
error. It seems like the verification of the password algorithm expects the password in a feasible manner. Any guides on how to do that? From better-auth code I can see:...
Solution:
Implemented the functions like the following ```ts import { scrypt, randomBytes } from "crypto"; const scryptAsync = ( password: string | Buffer,...

Generating sign in and sign up page

Hey Guys, Ive been working on implementing better auth into my project in my nextjs 15 app router project. when i create my sign up button using the better auth website, it outputs the code I have attached below. However, when i installed and initialised my project, it installed v4 of tailwind as the latest version. However, I have noticed that the better auth sign up template requires shadcn which isnt compatible with the latest version of tailwind. I had claude try output a version that does not rely on shadcn, but idk if it is good/will break my project. Could someone pls help lol...

cross domain cookie transport issue

i have my auth server (hono) with better-auth hosted on cloudflare, i want to be able to use that hosted server in my development too instead of running the auth server locally everytime i want to run my frontend, i set the cookies to same site none and secure but what happens after successful auth is that the cookie is set in my browser but when i navigate to a different page or refresh my page the cookies disapper, here's the config im using: ```ts export const createClient = (appName: string, baseUrl: string) => betterAuth({ emailAndPassword: {...

Migration with NestJS

Previously, I used a manual password validator with JWT in NestJS. Now I’ve migrated to BetterAuth. What’s the best way to migrate existing users to the new system—for both normal email/password logins and Google OAuth logins?

Does the phoneNumber plugin recognize manually created users?

When using the better-auth with phoneNumber plugin, if I create a user directly in the database with a phoneNumber, will an API call like authClient.phoneNumber.sendOtp and authClient.phoneNumber.verify for that number recognize the existing user, or will it create a new one?
Solution:
I'm pretty sure it finds the user based on the phone number

Is there any way to pass any flag to CTX (like query, param, body, etc...) in Google Oauth

I am trying to create the mechanism of organization invites and when the user is invited I have the invitation token I want to pass it in ctx so I can use it in my database hook, with email and pass signup I was able to send it in ctx.params but on Google signIn I am not being able to pass it, how can I achieve this? I have tried the onRequest and onSuccess and I was not yet able to do it...
No description

Automatically create subscription in Polar for organization

Is it possible to automatically create a subscription for an organization after it's created?

DatabaseHooks Session Create Before

```ts databaseHooks: { session: { create: { before: async (session) => {...

Does Better Auth use emailVerified?

Does the signed-in user's value of emailVerified change any behaviors of Better Auth? Or, is it up to the application to implement permissions and UI based on emailVerified? Or both?

Does database casing work at all?

In database you can provide object with db or dialect and there is also casing, but does it work? ```ts import { betterAuth } from "better-auth" import Database from "better-sqlite3" import { Kysely, SqliteDialect } from "kysely"...

Phone OTP Auth

How is the phone number plugin sending SMS? Can I use Twilio Verify to send the phone OTP? I need to ensure deliverability, thanks! https://www.better-auth.com/docs/plugins/phone-number...

Cookie Caching in Better Auth Not Preventing database requests?

Hey everyone! I’m using Better Auth with cookie caching enabled, and I’ve also turned on logging for my Drizzle DB. But on every page reload, I still see DB logs from Drizzle. Shouldn’t the caching prevent repeated DB hits?

Using the CLI in SvelteKit project

I am a bit confused since I followed the SvelteKit integration guide that recommends ```typescript import { betterAuth } from "better-auth"; import { sveltekitCookies } from "better-auth/svelte-kit";...
Solution:
I think right now the only way is just to comment out code that causes the CLI to run into issues,

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