Better Auth

BA

Better Auth

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

Join

bug-reports

help

Getting the full JWT token

So I'm trying to build a realtime chat app which uses asp.net with signalr on the backend. The problem is that to use it I have to be authenticated, where I configured it to use the same signing key as better-auth, but the problem is that I can't quite find a way to get the FULL JWT token to use to authenticate myself to the backend. Tried the bearer plugin and it just did what I was doing, but easier. So the problem is I can't find the FULL JWT token used. Is it even possible to get it?

How to list members in an organization

Hello. I was trying to make a nice organization dashboard page, and I wanted to list the members inside of the organization. Is this possible under the organizations plugin? Thanks
Solution:
Use authClient.organization.getFullOrganization and iterate over .members

CallbackURL faild

After signin with google I set callbackURL:"/home" and it suppose to redirect to http://localost:5173/home but it redirect to http://127.0.0.1:3000/home

Saving Additional information from a Generic OAuth endpoint

Hi all, been playing around a little with the generic OAuth plugin to hook up to an Identity provider and I have two questions I can't seem to find any potential resolution for and was hoping to get some help. 1) The refresh token expiry doesn't seem to save / populate. It looks like it returns in the OAuth token as "x_refresh_token_expires_in". Is there a way to overwrite the generic oauth default to save this to the database? 2) The returned id token from the provider supplies some additional properties I am hoping to snag in addition to sub / aud / iss etc. Is there a way to setup a hook to save these propertites out of the id token ?...

Populate username field with social usernames

Using the username plugin. How would I make the social links populate the username field? It seems standard behaviour is that Twitch is populating the name field with the Twitch username, and Discord is populating name with their actual first name. I would like so you log in with a social link and your username is set to your Twitch/Discord username. @Ping Any insight? Thanks in advance...

useSession returns null for data in Next.js

Client side useSession form Better-Auth Client returns null: ```ts const { data, error, refetch, isPending } = useSession(); console.log("SESSION DATA: ", data); // logs SESSION DATA: null...
Solution:
Are you sure the data isn't just pending? Because while it's pending you will get null.

overrideUserInfo? in GenericOAuth?

I see OAuth2 plugin got overrideUserInfoOnLogin and when seeing how that worked I noticed on GenericOAuth there is the similarly named overrideUserInfo which the interface describes as: ```typescript /** * Override user info with the provider info....

Can you handle subscription pricing tier changes and prorations using stripe plugin?

I wasn't clearly able to understand from the documentation whether or not this is possible. My guess is no and to use the stripe api myself?

Offline support for expo apps

so i'm building an expo app that is to be built on iOS, android as well as to be deployed on the web. i moved away from clerk seeing they've not made enough progress in heir offline support. i need guidance on what to do. i'm tring to build a local first business management tool and one of my requirements is that iw ould want to be able to open my application without necessarily having an internet connection. i thought with the sessions being stored on the user device using expo-securestore i t...

Does crossSubDomainCookies not work on localhost?

So currently i have a setup where my login is on localhost:5173/login. here i get my cookie when i go to tenant.localhost:5173/admin i dont have the cookie the domain says localhost even tho its supposed to say .localhost from my understanding? setup:...

How to sign out the user from server side

I'm using Next.js (App Router) along with the better-auth package to manage authentication sessions via cookies. I want to implement a logout functionality from the server side, where I remove the session cookie and redirect the user to the login page....

Reduce docker image size

Any improvements to reduce the image size? surely it shouldnt be larger than 2-300MB. its bloated requiring bun, python, and js. due to needing to run prisma client, and do prisma migrate at runtime hono + better auth + prisma 684MB...

Jsonb support in plugins

Hello everyone. I need to store a json in a metadata field. I can use the type string, but I can't search on that field as field.subfield.... Any workaround?...

TRPC support

Any examples with Next and TRPC? I need to create a monorepo with next and expo and I would like to use TRPC as well.

Getting users' organization details in JWT token

Hi! Is there a way to get the users' organization details (such as organizations the user is a member for or the currently selected one) in the JWT token claims, using the JWT plugins? Thanks!...

Im using the better-auth in a non-nextjs server to verify session and see this error.

error Cannot find module '/app/node_modules/next/headers' imported from /app/node_modules/better-auth/dist/integrations/next-js.cjs Did you mean to import "next/headers.js"?...

How to link Generic OAuth to existing user

I have a question about Generic OAuth account linking. Say I have a user [email protected]. I set up a Generic OAuth plugin to authenticate to Nylas, which in turn sends the user through an OAuth authentication with their Google account. But say the user's Google account email is [email protected]. Currently when user completes the Nylas authentication, better-auth is creating a new user [email protected], then creating a Nylas account record linked to that new user. But I want the Nylas account record to be linked to the currently-logged-in user [email protected] and not create a new user when the emails are different. I tried this in my auth.ts config but it didn't help:...

How to manage a stripe plan upgrade

Hi everyone, I'm trying to upgrade a user's subscription plan using Better-Auth and Stripe. Here’s the snippet I'm using: ```const { error } = await authClient.subscription.upgrade({ plan: planName,...

Inferring Additional Fields on Server

Hello, I added gender to my user schema and I would like to infer the User type so I dont have ts error anymore....
No description

Is it possible to get the user id from the cookie without having to verify to user and hit the DB?

Right now I have a call to the database that will check if the user with the id has access to the resource being requested. Because of this I need to get the session which can take ~200ms uncached. I don't really need to verify the user is valid before I get the resource and it would speed things up quite a bit if I could just do that at the same time as I am getting the resource. Is it possible to just get the userId from the cookie / apiToken without having to hit the DB first? Right now the code looks something like:...
Next