Better Auth

BA

Better Auth

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

Join

bug-reports

help

Multiple teams

What's the best way to support members in multiple teams?
Solution:

passkey plugin's endpoint `generate-register-options` gives me 401

A fresh new project. Followed exactly the guide on the website. Not sure if i missed anything.
No description

authClient.GetSessions() returning null for user data and session data

I have an issue where getsessions function of the authClient is returning null. I am trying to sign up/in a user with google. The auth flow seems to work ie I get a session, user and account stored in my database. I also get the onsuccess handler called after signIn. The issue is, the data is null ie const {data} = authClient.getSession(). I am trying to read the userid so I can send other requests to the database. Here is my auth context handler: https://github.com/zessu/honoapp/blob/master/packages/frontend/src/authContext.tsx issue on line 22 Here is the backend Auth config https://github.com/zessu/honoapp/blob/master/packages/backend/auth.ts...
Solution:
I fixed this. Issue was with the cookie settings , specifically domain settings thats why it was not being returned Anyone let me know if you have a similar issue I can try help

Enforce Email Domain Restriction with Google Sign-In

https://www.better-auth.com/docs/concepts/hooks#example-enforce-email-domain-restriction Is there an easy way to do the same as the example above, but when using Google as a social sign in? I use Google Workspace at my work and we have custom domains, so I want to be able to verify if we're logging in with a Google account from that workspace. I'd like to be able to change where I'm sending the user depending on their email. I've tried many things, like throwing APIError inside of mapProfileToUser or getUserInfo, but it doesn't trigger a redirection to /api/auth/error, which I could have short-circuited to maybe do what I want, but it didn't work out....

Error: The edge runtime does not support Node.js 'crypto' module

This error only come up after I added middleware Searched issue on GitHub , no report about it on better-auth (or I am blind) tried to search more info appears that next-auth also have same issue as better-auth I need help here: How to bypass it or we have to not use middleware until it fixes?...
No description

Social sign-in doesn't work

```tsx const res = await authClient.signIn.social({ provider: "google", fetchOptions: { headers: {...
Solution:
hmm. could it be your db connection?

Is it really necessary for database if I am only using Discord Oauth

I have been looking around but I saw database being a requirement, so I would like to know if I can do something about it necessary

Custom

Can i create custom credentials authentication like Auth.js/NextAuth.js?

Can't use @better-auth/cli when exporting a auth function

I am using Better Auth across my api (hono + cloudflare workers) and fronted (nextjs + vercel), so far so good however when i want to run the bunx @better-auth/cli generate i get the following error: ```bash $ bunx @better-auth/cli generate --config ../api/src/common/auth.ts --output ./src/schemas/auth.ts ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in BuzzTrip/packages/api/src/common/auth.ts. Make sure to default export your auth instance or to export as a variable named auth. error: script "db:auth" exited with code 1...
Solution:
you can call ```ts import { getMigrations } from "better-auth/db"; const { runMigrations } = await getMigrtions(auth.options);...

onApiError custom error page

I made the setting to make a custom error page, but when the error occurs, the /api/auth/error page still works, is there something I forgot to do about it?
No description

Better Auth Session Not Loading in TanStack Router Application

I'm encountering an issue with Better Auth sessions in my TanStack Router application. The session data appears correctly in network responses, but it's not being loaded or accessible in my React components. Project Setup: Better Auth version: 1.1.21 TanStack Router for routing...

is there any way to handle current session across all the app once

i want to display the current user in the home page but also check if the session exist to make a post request so ineed to get the session again in that component is there any way to handle session in a single compoenent or a single server function in next js

Migrate from next auth to better auth

Hello everyone, please I need help. currently I am working on a project. That’s not deployed yet and I am using next auth, but in next auth i can control the login function. So now I don’t know how can I control the login function in better auth, i want to implement my own login logic because in my case i dont have a registration method, only login via LDAP or Active Directory, So please if you know how to overwrite the login function share the code with me. Thanks...

Not requiring captcha for social signins

Is there any way to just not require it for social signins?

Internal Server Error when deployed to AWS

My Nextjs app works locally and when deployed to Vercel, however when I deploy to AWS via SST I am getting 500 internal server error for anything auth related. Is there anything special I have to do to get better auth to work in AWS Lamgda?

pass discord ID to session

I am trying to pass a users Discord ID through to the user object in session. I am aware of mapProfileToUser but not of how to use it to accomplish adding it to the session. I know how to add it custom fields to the session, just not how to get the profile object from socialProviders: { discord to custom session...

Organization inviteMember - Not Allowed to Invite

I keep getting a 403 - "YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION" This is a client component. User fills in the form to invite ```...
Solution:
Ok the solution is that you have to very carefully read the docs and not vibe code, lol. You have to use the default statements or the invitations feature will not work. So for example: ``` const statement = { ...defaultStatements,...

How to integrate BetterAuth with SolidJS

I'm using SolidJS for the frontend and Rocket (Rust) for the backend. I’m considering integrating BetterAuth, into my infrastructure. What would be the best approach to achieve this? Are there different ways to integrate it effectively?...

authClient.useSession() not callable in my Nextjs (15.2) client component

Hello. I use nextjs 15.2 and better-auth 1.2.4 I défined auth client like that:...

Using mongodb adapter and generateId creates id field in addition to _id field

using this config: ```ts import { createId } from '@paralleldrive/cuid2' const auth = betterAuth({...