Better Auth

BA

Better Auth

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

Join

bug-reports

help

Reset Password

im on making a reset password with temporary password flow But dont know where to put this function in order to set user password const token = new URLSearchParams(window.location.search).get("token");...
No description

Posthog identify after sign up

Hi all, I'm using posthog for analytics in my next js app and planning to make use of the identify feature (https://posthog.com/docs/product-analytics/identify). I use the email and password flow with email verification from better auth. It's pretty easy to set it up when a user logs in as I can use the "onSuccess" callback. However, I can't wrap my head around how to do it after a successful sign up. I know you have a hooks.after callback but it runs on the server side and posthog needs to call identify on the client side. Could you suggest what the best way to do it? Thank you? Here's my auth.ts ``` export const auth = betterAuth({...
Solution:
Hi, maybe try after hook in database. I use it to send a wellcome mail to the user after he sign up. https://www.better-auth.com/docs/concepts/database#database-hooks...

Avatar Upload Issue: Session Cookie Size and Upload Timing

We're facing a challenge with our avatar upload implementation: Problem: When a user uploads an avatar during signup, the base64-encoded image is stored in the session cookie, making it too large and causing the app to crash Potential solution: We need to disable cache for the Session cookie ...
Solution:
you can use before hook or upload the image prior to calling signUp and then pass the image link instead of base64 to better auth.

magic link sendMagicLink using astro request is undefined

Hi guys, Iam stuck for a while now. I dont understand when or why the Request is undefined. Email, token and url are getting printed but the request is always empty. ```ts plugins: [ magicLink({ sendMagicLink: async ({ email, token, url }, request) => { // send email to user...

Anyone managed to create a server side protected route?

I'm having a set of routes that need to be accessible only when the user is authenticated. As per the documentation, I'm trying to create a function that runs on the server. https://docs.solidjs.com/solid-start/advanced/auth#protected-routes I guess it will be enough to check if better-auth.session_token cookie is set....
Solution:
In an API route you use can get it from the request parameter passed in to the method. More generally you can get it anywhere on the server by using solidjs's getRequestEvent(). I will include some sample code below.

On-User-Behalf flow (Microsoft Entra)

I'm trying better-auth for the first time and like it a lot. But I don't get my head around some behaviours and would be super happy if someone could just point me in the right direction. I'm using Astro and Microsoft Entra only. No e-mail/password or other socials. What I'm trying to achieve:...
Solution:
So I switched over to Lucia and got it working. I was following another help thread in here, which got a similar problem. You might find your solution here @mikewilliams : I cannot copy the link.. dont know why. Discord doesn't let me. The thread is called "RefressAcceshToken in SocialProvider (Microsoft) and NextJs 15"...

Nothing happend on email sign-up

Hey, i tried implement betterAuth on my nestJS. Problem is very weird, i can't receive any error. There is my snippet. Do you know where can i start find any issues or logs?
Solution:
Ok, i found it, thanks @Ping the problem was that there was missing disabling bodyParser
No description

Stripe 1.2.7 restore issues

Hi, I'm Sveltekit, eager to test this new function out, thanks for adding it! I haven't had success yet, I have been able to cancel subscriptions as normal and everything else works fine. The request to /api/auth/subscription/restore is still returning a 404 Not Found error. is the server-side of this implemented or is it all on the client side? The user.id is being pulled correctly here: const { data, error } = await authClient.subscription.restore({ referenceId: session.user.id }); Thank you!!...

stripeSubscriptionId is not being populated

Hello, could you help me? I'm integrating the Stripe plugin but when completing a subscription the stripeSubscriptionId is not being generated. ```stripe({ stripeClient, stripeWebhookSecret: env.STRIPE_WEBHOOK_SECRET!,...

Hook into Post oauth login flow

How can I hook into the flow before better Auth creates the user and check, if the discord id ia regestres, if yes and there is no User then create it. Thanks!

Stripe Subscription Update Shows Error in Console but Still Works

When creating a Stripe subscription, an error is thrown in the console, but the update is successfully reflected in the database. The prisma model is automatically generated by the* better-auth* CLI.
Solution:
The issue was resolved after updating the API version. Thank you for your prompt and helpful response.
No description

Fixed OTP for phone number sign in

Hey. Is it possible to set a fixed OTP for a specific phone number? I need this for the apple app store review to be able to sign in.
Solution:
Sorry for being unclear. i mean fixed as being constant, but solved it. Just updated the verification record after sending the otp

Lambda Authorizer with Better-Auth

Did anyone try this integration yet? I intend to have better-auth authenticate the requests coming in AWS Gateway

What is the "token" returned by auth.api.signinEmail?

Hello, I use a custom endpoint for sign-in/email. The return of auth.api.signinEmail() is:...
Solution:
you most likely don't need to return it but it's safe to return

session object on databasehook

```ts session: { additionalFields: { isCompletedOnboarding: { type: "boolean",...

couldnt find organization.listInvitations

https://www.better-auth.com/docs/plugins/organization#list-invitations I couldnt find a function const invitationsR = await authClient.organization.listInvitations({...
Solution:
update to latest

Backend Solution Better-Auth Integration

Just want to know if anyone has tried to work with better-auth with a full-backend solution (i.e. not having any client-side SDK implementation)?

How to set a password if we are logged in via a provider?

I am trying to create an account management system, but changePassword requires the current password. but i logged in through google. how do I properly handle this senerio? I want to user to be able to set a password if they haven't already.

Handling error of forgetPassword call

Hi, I'm trying to handle the error when using forgetPassword but if I provide an email which is unknown, I can't catch the error. I'm seing this in the output: 2025-04-13T20:05:20.175Z ERROR [Better Auth]: Reset Password: User not found { email: '[email protected]' } Here is my code: ``` const handleResetRequest = async () => { setLoading(true);...

Provider invalid OAuth2 redirect_uri

I am getting an error when I try to sign in with Discord on my prod environment. I don't have this issue locally I get Invalid OAuth2 redirect_uri and I checked the browser logs ``` GET...
No description