Better Auth

BA

Better Auth

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

Join

bug-reports

help

onSuccess bug?

onSuccess requires 1s setTimeout before redirecting, otherwise the session is null. the documentation doesn't mention this, I was expecting that onSuccess means the session was already set, is this a bug? ``` await authClient.signIn.email( {...

In convex i get an error "Client Disconnected" in my logs everytime i try to connect

I can signup flawlessly but unfortunately if i try to signin (await authClient.signin.email({})) with the same credentials the api calls for "get-session" and "token" are 200 but the convex hook useConvexAuth still returns { isAuthenticated: false } and on the convex logs dashboard i instantly get the error shown in screenshot. I followed this tutorial : https://convex-better-auth.netlify.app/framework-guides/react My stack is Frontend : Vite-React-TanstackRouter and Convex for Backend/DB (I write them because i could find the revelant tags)...
No description

How can I use roles and permissions from the database to manage authorisation using the admin plugin

I have written server functions to fetch roles and permissions from the database and attempted to use them in auth.ts and authClient.ts. But it's not working. Please, anyone can help to fine how I use roles and permissions from database

What's the best way to check authentication? Can I check the session once in a Next.js layout?

I'm currently importing the auth client, getting the session, and checking if it exists. If not, the user is redirected to the landing page: ```typescript const session = await auth.api.getSession({ headers: await headers() }); if (!session) {...
Solution:
Right there is no way of hydrating the session on the layout but will be working on it for sure. Till then each of the page tree needs to fetch check on auth state is they don’t have ancestral relationship

Multiple better auth instances for MCP

Hey, want to check if this would make any sense or could cause problems. We're adding remote MCP support, so users will need to sign in with Notion and other providers to access their account via the MCP server. We don't want users to be able to sign in to the main app with Notion. This is purely for the MCP integration. So we were thinking to create a 2nd better auth instance just for this. Is Better Auth intended to be used like this, or will it cause problems?...

How are you supposed to handle errors on the client? API is very inconsistent

- I appreciate all the efforts the authors have put into making this library but I'll be brutally honest - Something as basic as error handling has absolutely horrible documentation - I am talking specifcally about handling errors in my sveltekit client that uses a separate express backend - Now before you point it, yes I have read the docs ...

Project specific api keys

Instead of associating api keys with users, i want them to be specific to a project What is the best way to acheive this?...

Create organisation after sign up is not working wihth soical sign-in

Hi, I'm trying to create an organisation with user database hooks. Creating an organisation is not working if the user tries to use social login in the login flow for the first time (where user creation happens in the user login flow). ``` databaseHooks: { user: {...

What is the type that returns auth.api.getFullOrganization()

@Better Auth What is the type that returns auth.api.getFullOrganization()? Can I explicitly define it, similar to export type Organization = typeof auth.$Infer.Organization;? it's defintly not that, because the full Org type sems to return a list of members...

Revalidating cookie cache after updating session

Hey I have a multi-tenancy setup with Nextjs and Better-auth (without using the organization plugin). I'm saving the user's active companyUuid to session and on the frontend side I call a Nextjs server function and update the companyUuid in the database session and refetch the session which kind of works, but after implementing the cookie cache the cache isn't invalidated. What should I do in this case? Or should I be implementing it differently? ```...

How to fix the superAdmin problem

I read the docs and it says custom admin roles needs createAccessControl. How do I define it in the access control. @Better Auth...

ownerAc as there is adminAc

I want to know if there is ownerAc , memberAc and where to import it from?
How do I use it @Better Auth @Ping...

Use with Svelte Kit

My better auth instance is in a hono server. Where should I use the client? server action?...

404 on /two-factor/view-backup-codes

my better-auth server is returning 404 for the /two-factor/view-backup-codes endpoint. And I'm not sure why. All the other endpoints for the Two Factor plugin are working fine (visible in /auth/reference). Would appreciate some help figuring this out. Thank you....

Failed login with X (twitter) getting unable_to_get_user_info & wrong scope with X Oauth

This is what my auth.ts file config looks like: ``` socialProviders: { twitter: {...

SSO Invalid Provider

Hello, I’m configuring SSO for a project using Better Auth (following the documentation: https://www.better-auth.com/docs/plugins/sso ). After the user logs in via SSO, the callback fails with the following error: Error Code: invalid_provider...
Solution:
There was a incorrect configuration of my app
No description

Get role in middleware

How can I access the user's role via session in next.js middleware?
Solution:
Found the solution: const session = await getCookieCache(request); const isAdmin = session?.user?.role === "admin";...

Account linking with the generic SSO plugin with EntraID

Hi all! We have organizations and each organization might have an sso_provider setup. For example, az organization might use the generic SSO plugin to setup their corporate EntraID. The problem I ran into is that Entra won't return an email_verified claim, this means that users in the organization who already have a user account before their first login through the SSO gets rejected with an account not linked error. https://github.com/better-auth/better-auth/blob/5e50205a3f9a7ee6608703f23d26a2b944a8cce9/packages/better-auth/src/oauth2/link-account.ts#L64 I thought fine, I will implement the linking feature for those users who won't be provisioned by Entra but were already existing, but I found that i can't use authClient.linkSocial on sso_providers which were created with the sso plugin. I simply get {"code":"PROVIDER_NOT_FOUND","message":"Provider not found"} despite the provider being available in the database. I found in the code, that https://github.com/better-auth/better-auth/blob/5e50205a3f9a7ee6608703f23d26a2b944a8cce9/packages/better-auth/src/api/routes/account.ts#L197C30-L197C45 the provider is searched in the socialProviders which doesn't include the providers created by the sso plugin. ...

Error login with google

When i try to login with my google account this error pop up , and if i try to use another account the app works fine...
No description

useActiveOrganization is returning null always

This does not work even if setting active organization id on the create and in manually in middleware also