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

Prevent Verification Email being re-sent on every SignIn

I use email verification in my app. Every time I try to sign in (before confirming my email), another verification email is sent out since the function "sendVerificationEmail" is called again. Is there any way to prevent this? I'd like to send only one confirmation email and then maybe allow the user to trigger another one manually....

Any way to set up a redirect URL after signups?

I want to implement something like clerk, in middleware I am adding query params of redirect_to=/dashboard or something like that, currently using router.push(), any native way to do so ?
Solution:
As of now you can pass a callbackURL : ``ts authClient.signUp.email({ callbackURL: /` })...

twoFactorTable

Is it still possible to set twoFactorTable? I'm not able to find the function under the server config but is see the others: ``` issuer: "issuer-name", skipVerificationOnEnable: true,...

Call success url on the authclient checkout

Just wondering if there is an option to simply call the sucecssUrl in the autClient api rather than passing it in the config file. For our use case I'd like to redirect to the first video of a course, so something like this is handy 👍...
No description

Can better-auth client be used from backend?

Hi. Can the better-auth client be used from a backend so that better-auth can replace existing auth functionality with minimal frontend changes, or does the client have to be called from the frontend?

getSession gives null after google login on deployed app

Hey everyone, I'm running into an issue with authentication and could use some help. Tech stack: Backend: Hono (Deployed on workers) Frontend: Next.js (Deployed on vercel)...

Rate Limiting Does Not Work

I'm trying to test rate limiting on dev, but unfortunately it doesn't limit anything. This is my config: ``` rateLimit: {...

API `verifyEmail` problem

I'm encountering an issue with an email verification process in my TypeScript application. Despite the API response look like successful operation (a set-cookie header), an APIError is being thrown. better auth v1.2.10 ```typescript...

SQL error when exchanging the token (Microsoft Auth + MSSQL + NextJS)

Hello! I am trying to switch from AuthJS to better-auth but i am stuck with an SQL error. It happens on the http://localhost:3000/api/auth/callback/microsoft callback (with the code parameter). It looks like better-auth is trying to save some data received from Microsoft with an unexpected format...
No description