Better Auth

BA

Better Auth

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

Join

bug-reports

help

can we have callbackURL with emailOTP or passkey login?

i see callbackURL when using passwords but i am wondering if callbackURL can work in passwordless login scenarios?

Invalid drizzle schema for `defaultValue` of additionalField with type `string[]`

Below is how my src/auth/auth.ts tooks ```ts export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", // or "mysql", "sqlite"...
Solution:
nevermind

Magic Links vs EmailOTP?

I don't understand the difference between those 2 auth methods. isn't the same?

how to perform extra verification before allow user creation

i want to block disposable emails from signups. can i add pre-signup logic or disable client based signup api?

Better-auth ratelimit vs upstash rate limit

I am wondering if there is any meaningful difference in using https://upstash.com/docs/redis/sdks/ratelimit-ts/gettingstarted vs using better-auth rate limiting with redis as a backend (using redis.get() and redis.set()). I know that the upstash lib will use an efficient windowing algorithm. I could use the upstash middleware "upstream" from the better auth route handlers but I am not sure how supported that is....

Integrate fullstack frontend and multiple APIs using better-auth and same database

Hi! I'm starting to write and application that will use a tanstack start fullstack frontend plus about 4 different APIs. I just met better-auth and it looks like a great solution for centralizing authentication and authorization. I set it up in my applications, put 'em calling the same DB and with same better-auth-secret, so I believed I would be able to use a frontend-generated token to authenticate in API. But I'm being 401d in API requests. I'm using NestJS + better-auth lib for creating the APIs. Tried calling it using Authorization header (bearer token) and some variations with cookies, with no success. The token I'm sending is the one also saved in session table (in database). Is there an easy way to make it work? I'm thinking I could create a custom nestjs guard to read the token and authenticate it in the database, but if I do it I feel the 3rd party lib won't be needed....

Nextjs - Refetch session every time page changes

How am i supposed to get the latest session data on every route change using useSession? it uses that same get-session throughout every route

Captcha plugin: verification only on sign up (email otp) not sign in

E.g. i want existing users to sign in without needing the captcha verification (it hinders auth flow), and only let new sign ups verify themselves. The send email otp verification does not differentiate between sign in and sign up, at least not on endpoint path, which is what is passed on the captcha plugin. Is this perhaps possible in hooks?...

what is the correct way to check if email exists

i see isUsernameAvailable - what about email. I was thinking to ask email of user first, if it exists, proceed to login page, otherwise proceed to sign up. It's not clear what is the cleanest way to check if email exists in our db.

How to prevent user sign up from Oauth provider

I only want to allow certain groups when on boarding different organization to sign up?

can i use better-auth in a passwordless way?

is it possible for me to create a website that uses magic links or passkeys without any oauth or passwords?

Returning Errors From OTP

Looked through docs and couldn’t find how to return error details for otp. sendOTP doesn’t allow a return and throwing an error just gives the client 500 code with status text “”. Use case here is managing twilio verify errors and want to pass those onto the client. I’d be fine mapping their codes to better auth codes just don’t see how to to that, thanks. Happy to share code as well if it helps explain.

Does better auth supports Docker hosted local database ?

Helo I am suing docker, and Nexjt,s Here is my setup 1. I am using dockerized posttres which is running and working perfectly with prisma and I tested by seeding (inserting) some randomw data. 2. but when I connect to better auth it shows me one single error which is this below one ...
Solution:
Then I will work that and then I use better auth methods like signUp with email or other methods then it gives me that Errro. Did u do this and worked for you ?...

OIDC Plugin data migration

I have in my database the ids of the users from my previous authentication provider. I want to migrate these users to a my new better-auth backend so I can handle this data there. I've added a button where they can link the account and this is working perfectly. However, I wonder if I can migrate the users from the old to the new app, just with the users ids. I saw that in the tables better-auth saves some tokens, but not the id directly. So I would like to know if there's a way to do this migration, without the users to manually connecting their accounts again. Thanks for the help....

Error Code: email_not_found

Google oauth works fine, but we I try to login I get email_not_found error. Any idea why it happens? ```ts const config = { database: {...

Endpoint to Fetch Organization with all teams

Is there an endpoint to return all teams inside an organization? I want to get an object including the organization and its teams, like this: { "name": "lorem-organization", "slug": "lorem-org",...

The model "user" was not found in the schema object

I'm not sure what is going on, I've already specified it in the schema: ```ts export const auth = betterAuth({ plugins: [bearer(), jwt()],...
Solution:
Well apparently the TS output was originally /dist/app.js, but somehow - and I still don't know why/how, it started outputting to /dist/src/app.js, so basically I was 'working' on an older code.

Error when running nextJS demo app (Module not found: Can't resolve 'better-auth')

I'm trying to run the nextJS demo app, but getting this error after pnpm run dev I did the following steps per the README: ```...
Solution:
Got around it by changing package.json to import packages from npm rather than references to the mono repo's workspace: and catalog:.
No description

Redirect Ignoring baseUrl?

I have a next.js app, locally it all works fine but when I put it on a server with nginx for https, authentication (specifically Twitch) it redirects to localhost:3000? No matter what I do I can't point the redirect back to the SSL server. When I change stuff locally it comes up with some sort of cross origin error. I can't tell if I am missing something blatantly obvious...
Solution:
Twitch is just sucky, there is a captcha above the client ID which you need to click to enable the save button:
No description

Monorepo

Hey again guys. I have a monorepo project with hono server and nextjs frontend. Im trying to check the user session in RSC with authClient, but im geting null. Can someone explain to me why this the happeing. getSession return null while useSession return the user object.
No description