Better Auth

BA

Better Auth

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

Join

bug-reports

help

Can not change the issuer and audience of JWT header and also the payload

So tried to change the issuer and the audience of my jwt config by following the documentation but it's not working as expected here it's my config ` 'plugins: [ jwt({ jwt: { issuer: env.BETTER_AUTH_URL, audience: env.REDIRECT_PROXY_URL,...

How to implement invite-only registration flow with better-auth?

Hello, I'm looking for some help on how to implement this use-case. Here is the general user creation/registration flow I want to implement:
1. Existing admin user adds a new user by entering their email (and possibly name and role). 2. The new user receives email with a welcome message and a link (time limited) to complete account setup. 3. After clicking the link, the user is redirected to a page where they can enter a password and/or link their social account....
Solution:
we'll have sendInvite functionality in the admin plugin soon but magic link or forgot password for the time being should work fine

How can I make better-auth typesafe?

I currently trying to make a list with all members and invitations, but I constanly running in typing errors.
No description

kysely + organization setup

Hi, I'm evaluating better-auth and it looks great! Are there any code examples of email + password & organization configured alongside using kyself to define other Tables etc? It feels as though organization and the other entities are under the umbrella of better-auth but I'd like a single layer to interact with DB stuff where I'd consider Organization to be DB

Question on authorization

Hey, I have a stupid question. However, I can't figure it out at the moment. When I make an api call (from my api with hono). The following always returns null: const session = await auth.api.getSession({ headers: c.req.raw.headers });...

2-step login flow and organization question

Hi! I am trying to implement a 2-step login flow where the user first inputs the email address, then depending on the email domain and if the user is already provisioned follow-up with the second step. My questions:...

Extending user object when calling getFullOrganization()

Hi everyone, I added an additional field (phoneNumber) to the User property. How can I include that additional field in the user object when calling getFullOrganization()? Does better-auth provide this feature, or do I need to create my own custom?
Solution:
yeah the org plugin doesn't support this currently.

MongoDB Error Duplicate key

I sometimes get this error when authenticating with MongoDB: ``` errorResponse: { apps/backend dev: index: 0,...

Running npx @better-auth/cli@latest generate does nothing.

I'm trying to set up my user schema and using drizzle and pg. When i run the command to create the migration file, it just installs the cli and nothing happens. Doesnt matter if i add flags or not. Has anyone experienced this?
No description

nextjs error w/ betterauth on build

hello, every time i try to build my app on nixpacks in docker, i get this error from next. i am so lost and have no idea what to do.
Solution:
so it looks like i forgot to add my .env in my docker container
No description

Help with Seeding Existing Users into Better Auth

Hi everyone, I’m looking for guidance on integrating my existing users with Better Auth. My users are already formatted in JSON, all using email/password authentication, and their passwords are already encrypted. I’ve already set up Better Auth’s options to work correctly with BCryptJS. My setup:...

Dealing with session expiration in a React app

I need to have the UI reflect the logged in state at all times. useSession will not trigger if a session expires (see: https://discord.com/channels/1288403910284935179/1353810672458403920/1353820038154551469) I'm trying to figure out how to deal with this, here's my current plan: 1. Store the current session in a React context. Keep it updated for sign in / sign out via useSession....

Facing difficulties with NextJS + Hono + D1 (Cloudflare stack)

Hi I am trying to make better-auth work with nextjs + hono in the cloudflare stack. But I'm having some difficulties doing so! Main goal is: - Nextjs should be deployed to Cloudflare pages. - Hono should be deployed to Cloudflare workers. - Will be using Cloudflare D1 as database....

How to Ensure Organization List API is authorized

I'm currently trying to use Better Auth and pair it with TanStack Query to optimize request caching as I want to dedupe multiple of the same requests that I see firing in my application. The question I have is, instead of using the client.useListOrganizations hook API that the docs recommend, I am using the raw client.organization.list API and wrapping that within the TanStack Query function like so: ```ts...

delete or clear cancelled invitations

is there no option to delete or clear cancelled invitations didn't find anything related to delete invitations. this is what i found in index.d.ts guide me, if i'm wrong. readonly invitation: readonly ["create", "cancel"];...

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