Better Auth

BA

Better Auth

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

Join

bug-reports

help

How to add custom fields on Sign-up?

How do you add custom fields to client side functions like sign-up? I am working on a sign-up form in nextjs app router and I have better-auth working with the basic email, password, name, etc. fields using: const { data } = await authClient.signUp.email(...

stripe plugin & Polar plugin for payment

if i use stripe plugin & Polar plugin tgt , will there any problems?

Cannot verify TOTP after successfully setting up 2FA, getting `INVALID_TWO_FACTOR_COOKIES`

I can successfully enable TwoFactor, show the QR and backup codes, and verify it with a generated code. This sets twoFactorEnabled to TRUE for the user. However when that user later logs out and back in, and needs to verify their 2FA TOTP code, I get this error INVALID_TWO_FACTOR_COOKIES. No two factor cookies are being set anywhere, and I have tried to log them but they aren't generated by the enable nor verify TOTP in my totp/setup routes. What could be the issue? Thank you....

how to listUser from admin plugin?

I'm having trouble listing the users of my application using the admin plugin, I used the code provided in the documentation but I'm still having trouble.
Solution:
On the server, you must use auth.api
No description

BetterAuth as OAuth2 Server

Hi everyone, as I have recently read more often the requirement that BetterAuth is used as an authentication server and e.g. is hosted on another subdomain and serves as an identity server, and I also have the same requirement myself. I wanted to ask if it is planned to develop BetterAuth itself as an oauth2-oidc server in the future, because the current procedure (I think the only possibility is to put the auth cookie on the main domain) is rather unattractive and an OAuth2 server would have some advantages and would be a clean solution....

Can i use Better-auth api in nodejs which exposes my auth route to frontend on flutter

i am want to use better-auth in nodejs as server side auth and expose my api to frontend which is in flutter can we do it

How to handle deleted user?

I have a next app set up with auth using better-auth. I'm using basic middleware like this ```import { getSessionCookie } from "better-auth/cookies"; export async function middleware(request: NextRequest) { const session = getSessionCookie(request);...

genericOAuth discoveryUrl TypeError: Invalid URL

# SERVER_ERROR: [TypeError: Invalid URL] { code: 'ERR_INVALID_URL', input: 'undefined' }
POST /api/auth/sign-in/social 500 in 1873ms
# SERVER_ERROR: [TypeError: Invalid URL] { code: 'ERR_INVALID_URL', input: 'undefined' }
POST /api/auth/sign-in/social 500 in 1873ms
...

How to login right after signing up with OTP email?

Does betterauth have a way to create a session from the BE immediately after signing up with email OTP?

Prisma Adapter not generating Additional Fields for Organization

I had a lot of work with my config auth file, the modelNames work, the aditional fields for user work, but the custom field names and the additional fields are not being generates correctly using the prisma adapter:

I am gettng internal server error and not understanding why, how to get logs

anyway to debug this?
GET http://localhost:3000/api/auth/get-session 500 (Internal Server Error)
GET http://localhost:3000/api/auth/get-session 500 (Internal Server Error)
...
Solution:
That line is outputting the result of a GET request I would imagine the 500 is emitting some error to the log server-side? Are you sure there's nothing else in your console? You could try adding logging to your Next.js API route handler like this and interrogating the request to see if anything looks odd: ...

Managing Device Identifier Cookie: Where to Handle and Refresh It?

Hey everyone! šŸ‘‹ I'm implementing a device identifier system for user devices — even for users not logged in. Right now, my plan is:...

Failing to extend context via createAuthMiddleware

I am passing organisationName to the auth.api.signInSocial method on the server. The middleware catches this argument however I cannot succeed at passing it so it's available in the database hook. How can I solve this? Thank you....
No description

Stripe plugin with organizations, did anyone get it to work?

The docs mention being able to use the stripe plugin with organizations, but when trying to set it up the "stripeCustomerId" field is still added to the users table instead of the organizations table. How can I get around this? It feels like organizations support with stripe is a half baked afterthought atm....

Requesting permissions for Discord Bot using OAuth2 Login

As part of my social login with Discord I get the bot scope and I was wondering if there was any way for me to set the permissions to the discord bot using the social login.

Auth Client vs. Server-Side Authentication

Is it recommended to use the authClient or rather do authentication server-side? In general, I'd prefer server-side authentication. But the rate limiting (which is only available on the authClient) sounds very convenient honestly. Is there a best-practice / recommendation?...

Session cleanup

Is there any session cleanup mechanism? Or do I need to manually clean them up? I noticed sessions have expiresAt, but they don't get deleted from the DB once they expire....

Auth not working across completely different domains (app)

I'm trying to set up authentication where users log in on one domain and use the app on another completely different domain (think auth-service.com and my-app.io - totally unrelated domains). My setup: - Auth server on a.xyz - Main app on foo.abc...

Session is linked to wrong user when using OAuth

Hey everyone, I was trying to integrate a NextCloud OAuth to my Next.JS v15 application using Better-Auth. Everything is working fine, except for one little thing. When I use the OAuth login function from Better-Auth, I get authenticated and the user data is fetched from my NextCloud. I created a "profile" page to display all the user and session data, just for testing purposes. When I check the page, I always get the user, that I first signed in with. I logged in with a normal browser window and a private browser window to check the functionality. But I always get the user data that I first signed in with. When using the credentials provider that I set up, everything is working fine, only the OAuth with NextCloud is causing issues. Does anyone have an idea, what could be the problem or how I could fix it?...
Solution:
Found out what the issue was... Nextcloud was not giving me a valid email address through their API. Therefore the two users were created using the same email address, which let better-auth think, that they are the same user... Very stupid of me...