Better Auth

BA

Better Auth

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

Join

bug-reports

help

golang backend with nextjs cookie check.

I have created better auth server in my nextjs client app and want to integrate with a golang api service, but i don't know how to extract the cookie in my middleware, how to extract data from a cookie. I have tried jwt plugin as an alternate solution but still can't figure out how to extract the data correctly. I need to use cookie if possible....

Social Sign-in Invited Emails Only

Hi guys, i am working on a project where the signups are disabled and allowed only to the invited emails. for email password signups i have implemented it with hooks, but the issue coming is with social providers. i have listened to the context in after hooks. and throwing the error in case unauthorized with apierror and its fine but on server's endpoint and when i used ctx.redirect with throw or even return it doesnt work and let the user go through. this is my hooks config for both email/password and social provider: hooks: {...
No description

I think there is some type error

It does work fine but it show type error of Image being not present in signUpEmail through server API. Before the last update it used to work fine
Solution:
Type errors are present in any version above 1.2.5, Latest safe version to work with right now is 1.2.5 (based on my opinion)
No description

Additional fields missing from User type

I have added 2 additional fields to better auth with this code: ```typescript export const auth = betterAuth({ appName: 'Test', user: {...

How to refresh JWT manually

I understand that the JWT may expire before the session expires. In this case, I check whether the JWT is expired before I issue a new JWT. I've tried this method so far but no avail: - getting the session using the expired jwt so I can call api.getToken by placing the session token but no avail as calling getSession only returns null ...

[OIDC] `offline_access` invalid scope

Using BA OIDC plugin, from an OIDC RP (Auth.js on Next.js app) I am requesting the offline_access scope but get GET /api/auth/oauth2/authorize?error=invalid_scope&error_description=The%20following%20scopes%20are%20invalid:%20offline_access 302 in 26ms BA OIDC plugin docs say that offline_access is in the default scopes array (openid profile email offline_access). Am I missing a BA config option, or is it an issue on the RP side?...

Issue with sign up using express

Hi, I have been running in to an issue where my express server returns 422 Unprocessable Entity any time the client sends a sign up request. I have included my prisma schema, better auth config and my index.ts file (I have pretty much copied exactly whats on the better auth docs). Looking at the incoming requests on the express server, I can see the sign up requests come through however I noticed that the request body was undefined. Looking at the actual request through the network I can see that body is included in the post request. I have no issues adding data to the db manually through psql. Any ideas on what is causing this issue? ...

Auth service in microservice architecture

I'm trying to build a Hono backend setup with two separate services: One serves as the auth server that handles all user-related logic (base path: /auth), and the other handles business logic (base path: /api). In production, both will be hosted on the same domain. Locally, I'm using localhost:3000 for the business logic and localhost:3001 for auth. Currently, I’m able to log in with Google OAuth via the auth server from the frontend but when I try to fetch data from the API backend, the session is null, which results in a 401 error. ...

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