Better Auth

BA

Better Auth

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

Join

bug-reports

help

On-boarding step after social login

Hey! I m using google social signin and i give new users the 'pedning' role attribute in my database, I want to redirect these type of users to the onboarding page whenever they try to access anything in my app. where i collect additional infos about them such as to setup a displayname. , so basically not allowed to skip this step, then i change their status to something like 'member'. i want to know if there is a way to get the authenticated user data in my middleware so i can read their role status and redirect accordinly isntead of spamming all my pages with this check ? or any other method. thank you !...

why the ipAddress config is used

at the betterAuth we have config for ipAddress ipAddress: { ipAddressHeaders: ["x-client-ip", "x-forwarded-for"], disableIpTracking: false },...

Re-sending verification link after verification token expires

What's the correct pattern to allow re-sending a verification link if the user waits until after the verification token has expired to click the verification link? (1) - UX pattern - I could check the query string for error=token_expired and provide some UI where they can enter the email address they signed up with to get a new verification link sent to them. Is there a better UX here? (2) - generating verification token - not sure how to generate the token that sendVerificationEmail expects...

300+ type errors in better auth packages when attempting to build the project

When I attempt to build the project with tsc (node+express app), I get 321 type errors from better auth packages.
No description

Is there a way to use the permissions API without admin or organization plugin?

Just wondering about the above, I liked the permissions api built into those plugins, and organization doesn't work 100% for my use-case.

Cookie not being set when using live lambdas

hey using a live lambda to proxy better auth to aws, however the cookies are not being set when calling authClient.signIn

Session still active after calling authClient.revokeSession

I've got a button that does this: onClick={async () => { const res = await authClient.revokeSession({ token: session.token,...
Solution:
Found the solution. I had this on my auth.ts file that was preventing the session to be immediately terminated: export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", // or "pg" or "mysql"...

403 error when listing user from superadmin role

auth.ts ```tsx user: { deleteUser: { enabled: true,...

Use auth on client or server (NEXTJS)

Hey, for security and optimization reasons, should I use server-side authentication (e.g., await auth.api... in a server component) and pass the result to the client component when needed, or is it better to use the client-side authentication directly (authClient)? In which cases should I use one over the other?...

better-auth organizations

When running organizationCreation's beforeCreate and afterCreate I don't see any request being passed in. It's only the organization details even though I am passing in the headers directly to the api (because I'm calling this from the server). ```ts // Organization plugin setup organization({...

Access token from Social Login

I am migrating from Supabase. Everything works well until I tried to find out how can I get the provider token (from Google) after a successful login. I am using more roles on login and then after I want to use the token to authenticate to some Gmail APIs. I tried to get on authClient.useSession and authClient.listAccounts() . Is there a way? I am using Hono on backend and React with Vite on frontend....
Solution:
Better Auth doesn't expose the provider tokens on the client. You can make an endpoint and fetch the accounts table.

Change password from the server

how do I change the password (from the email + password credentiales) from the server? My understanding what that authClient is meant to be used in the client and that, in the server, I am expected to use auth.api.changePassword, as in: ```ts...
Solution:
You need to pass the headers of the user making the request.

Set active org on login

I want each user to always have one active org set when they log inn, no user should ever find themselves without an active org. Docs at https://www.better-auth.com/docs/plugins/organization indicate that I can use a database hook to achive this ```js export const auth = betterAuth({...

How to save ip addresses into the session table

Do I need to make a few extra settings? IP addresses are not being written to the database.
No description

you are not allowed to list users 403 error

i want to create superadmin for the owner of sas project, auth ```tsx additionalFields: {...

Stripe: how can we renew a cancelled subscription

I am trying to find a way with better auth to access the stripe billing portal again after cancelling a subscription, right now better auth throws an error when the cancel fct is called but the subscription is already cancelled, and from what I know this is the only way to access the billing portal from better auth

How to log sign-in, sign-out, and errors?

Hi, How can I log user logins, logouts, errors, and other actions in the Better Auth library? I’m using it in a Next.js. Is there a built-in way to handle logging, or do I need to implement custom event tracking? Thank you...

Cant delete API_Key

I get 404 when using the delete. _ const handleDelete = async () => { if (!selectedKey) return; ...
No description

Feedback on Using Hooks for Email Verification After Sign-In

Hey everyone, I’m working on a project where I need to manually verify a user’s email on their first login and then update an external system with the user's application status afterward. I’m using a hook after sign-in to check if the user’s email is verified, and if not, I update it and then send an external status update....
No description

Why does the session disappear after refresh?

Here, I am retrieving the session from authClient, but when I refresh the page, the session data disappears. What is wrong here?
No description