Better Auth

BA

Better Auth

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

Join

bug-reports

help

signup auth flow

so I am building a signup auth flow which goes like this: screen 1: name, email, phone (either phone/email or both)...

how to get access token to access discord api

currently i got an issued with accessToken with auth discord can you help me ?

google sign In Error Invalid code, ENTIMEOUT

Frontend: Nextjs Backend: Expressjs tried to login but got this error after redirect from google better-auth v1.2.12...
No description

Deciding weather to use Better-Auth

So I've been working on developing an app for my church to use as a member portal. It's just me developing this app and I have very limited monetary resources. That's okay though because our church is also relatively small. Anyways, besides the point. I have very little backend experience, but am somewhat experienced with frontend stuff. I've setup Clerk for my app already (it's a Next.js app I've built over the last couple of weeks, I'm currently hosting on Vercel's free plan), but I'm beginning to regret my choice considering the limitations they place on free users (and there's absolutely no way that I would have the funds to pay for their paid plans.) (see above)...
Solution:
It does really depend on what features you want out of better-auth, if you're using Clerk and not on paid plan then I assume it's nothing too specific thus it won't be too complicated to use better-auth. Most of better-auth's features are very straight forward and easy to implement, it's just a matter of getting an understanding of how better-auth works conceptually and that should get you on a roll. What features are you intending on using?...

stripe plugin doesnt seem to work

Hey, i've tried integrating the stripe plugin and i just keep getting this type error: There is a issue on github about this but it's just saying that this happens because of a version mismatch. ``` 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'....
Solution:
The issue occured in the tsconfig file. The error seems to only occur when module and moduleResolution is set to NodeNext This is the config that builds properly and doesnt throw the stripe plugin errors: ...

Expo Client Deep Link Security: Preventing Session Hijacking

I understand the typical sign-in flow when using the Expo Client looks like this: 1. A user visits /sign-in in their browser. 2. They are redirected to accounts.google.com. 3. After successful authentication, they are sent back to /callback....

Better Auth + Expo GO

Hey everyone, I'm quite new to Better Oath and ExpoGo, so it might sound like a newbie question. After a lot of investigation with Cursor, Gemini, and looking on the web, I couldn't find my answer, so I'm asking for help here. I'm stumbling upon a problem where I want to set up Discord authentication using BetterAuth in my app and I want to test it with Expo Go. I'm currently working on a mono repo, so my backend is defined in Next.js and I have a web app to compare and test with. BetterAuth works pretty well with it, whether it's locally or on Vercel, but I cannot manage to make it work on the app. The problem is as follows: Whenever I try to sign in with Discord on the Expo Go build of my app, the Discord authentication window opens, I put my credentials, and they are validated. But when I'm redirected to the app, the session is not updated, and not considered as logged in....

Getting error only in production and not locally

Getting this error in production ``` SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'serialize') at h (.next/server/app/api/chat/route.js:4:53602)...

Show API Reference (openAPI plugin) only in development

Hey, how can i conditionally show the API Reference only in development?

authClient help

How to make it so, with auth-client signUp, i can insert other stuff than email and name?

generate cli show no output

no schema generated in schema.ts file, path to schema file is (./server/db/schema.ts)
No description

OTP password reset

is there a method to verify the password reset OTP sent to user? according to the current better auth password-reset flow with OTP we need to send OTP + new password + email and it should work, but our flow requires the OTP verification before showing the password inputs for the user. i've found a method called getVerificationOTP but that also re-sends a new OTP for the user and returns ...
Solution:
I believe the OTP is already saved in verification table of your db

Finding Drizzle schemas for the better-auth "admin" plugin

I'm working with a Turborepo setup using Bun.js and I've placed my better-auth setup in a @repo/auth package. I'm running into an issue where I can't get the @better-auth/cli migrate command to run, so I'm trying to figure out how to set up my schemas manually to use the "admin" plugin. I checked the better-auth repo and found the base schemas here: better-auth/better-auth/packages/better-auth/src/adapters/drizzle-adapter/test/schema.ts Use code with caution....
Solution:
I think that all you need is to follow the core schema here: https://better-auth.vercel.app/docs/concepts/database#core-schema And then add the schema here: https://better-auth.vercel.app/docs/plugins/admin#schema...

Getting 405 on Vercel

I am trying make betterauth to work on Vercel, but for some reason all calls to /api/auth/* return 405 Method Not Allowed. Works locally, other endpoints work on Vercel. Using Next.js 15 and better auth v1.2.12
Solution:
Oh nevermind, I had incorrectly configured vercel.json file with this line. Deleting the file solved the issue
{ "source": "/(.*)", "destination": "/" }
{ "source": "/(.*)", "destination": "/" }
...

Prevent users without Stripe subscription from hitting API endpoints

I want to ensure users can't hit certain API endpoints without an active Stripe subscription. Is there a better way than checking the subscription table on each request in middleware?...

2fa cookie issues

POST /api/auth/two-factor/send-otp {"code":"INVALID_TWO_FACTOR_COOKIE","message":"Invalid two factor cookie"}...
Solution:
nextCookies(), has to be the last plugin

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 ...