Better Auth

BA

Better Auth

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

Join

bug-reports

help

Discord Invalid Scope

Hello. I was attempting to add an additional scope, activities.read, under the Discord section and I keep getting an error - Is there any workaround/fix to this? Thanks! P.S. The scope with identify and email is okay but whenever I add the one mentioned previously, it just throws an error....

2FA (Two Factor) isn't working returning 401 Unauthorized

I am trying to use TOTP authentication in my express app, I already added the necessary configuration in my backend's better-auth instance as well as in the frontend's react app, but everytime I try to enable to enable two factor, it returns a 401 response even though I am freshly logged in and the better-auth session is present in the cookies. I made sure to add the plugins in both server and client side, the issuer value is the same as well as the password value, but even with all of that, it doesn't seem to work. I tried both authClient.twoFactor.enable() and authClient.twoFactor.getTotpUri() but they both aren't working, here is simple example I working with: ``` function TwoFactor() {...

Magic Link not working with InstantDB (better-auth-instantdb)

Hi! Thanks for this library. I've ran into an issue with Magic Link functionality. The magic link is being sent to my mail, but the verification process is not working. The $users are not created when using a magic link. I do see that "users are being created", but maybe this magicLink plugin is not working well with instantDB. SERVER_ERROR: Error: $users entity not found: a03a0d5f-335f-46e1-878c-4e4d1f880106...

Best practice for preserving intended URL when redirecting unauthenticated users in Better Auth

When an unauthenticated user visits a protected page (e.g. /dashboard), my Next.js middleware detects that they are not signed in and redirects them to my sign-in page at /sign-in. A common practice is to preserve the original URL in a query parameter, such as /sign-in?redirect_url=/dashboard, so that after the user successfully authenticates, they can be redirected back to the page they originally tried to visit. What is the best practice to implement this pattern when using Better Auth?...

How to get env values from vercel?

Im using mongodb and deployed in vercel But social login failing because mongoDb uri is coming undefined in deployed version At the local working fine Added next.config.ts with env{} and added values in the environment section, redeployed...

getSession return null, but only when deployed

Hello, im building an application right now. frontend: sveltekit on cf worker backend: hono on cf worker...

Is BetterAuth a good fit for acme domains multitenancy?

I am building an LMS platform that provides unified authentication experience and must support dynamic acme domains configured by organisations. E.g. similarly Coda.io does for published docs. These domains are automatically verified and activated once DNS is set up by a user. So, the questions is: does BetterAuth provide the needed features for this? I plan to deploy in Vercel? Are there any pitfalls, did anyone have experience building this types of enterprise solutions? Please give me a honest and complete answer with references to docs if possible....

Cloudflare Workers - /auth always returning 404.

Hey, the request is able to entered on the route but better auth always returning 404. Hono route: `app.all("/auth/*", async (c, next) => { if (c.req.path.startsWith("/auth/")) { // Changed to /auth/ to avoid matching /auth exactly...
Solution:
this is how i do it `app.on(["POST", "GET"], "/api/auth/**", (c) => { const envi = env(c) return auth(envi).handler(c.req.raw)...
No description

How do I handle redirect for MCP?

When Using the MCP plugin, if I am authenticated in my web-app I get redirected right away to cursor or MCP client, but when I am not authenticated, I get taken to the sign-in page, and then I sign in with google and I get redirected to a page where I need to manually copy the url and paste it in the browser in order to get redirected, how can I fix this?
No description

Setting up email and password authentication on sveltekit using form actions

Hello , I have been trying to setup authentication with email and password using sveltekit form actions and superforms. The onerror method gives undefined as the context error message even though data is being passed successfully . ...

DeleteUser - How to know what to provide?

Hi all, I was looking to upgrade BA to latest version, but my test are failing with the new delete flow. I have setup the email, but now with "user with password" it don't work. How should I know what I should ask to the user to provide the appropriate data to deleteUser call? ...

"USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER” error code is not included in authClient.$ERROR_CODE.

"USERNAME_IS_ALREADY_TAKEN_PLEASE_TRY_ANOTHER” error code is not included in authClient.$ERROR_CODE. Is this a specification? There is no other "COULDNT_UPDATE_YOUR_EMAIL"....

additionalfield: unique - custom error

Hi guys is there any way to return custom error message from the auth.ts that is set to unique? user: { additionalFields: { employeeID: {...
No description

OAuth provider

I want my app (let's call it "XYZ") to become an OAuth provider, meaning that I'd like other devs to be able to integrate "Connect/Sign In with XYZ" on their own apps. For this I see two main points: The users are redirected to XYZ's consent screen when they press the "Connect/Sign In with XYZ". They are prompted to enter the credentials / sign in with their XYZ account (if they have no session saved). This is very straighforward and it's very clear to me how to do this with better auth. The user is redirected back to the original app with a an access token (or a code if PKCE) and requests protected resources to XYZ's API by sending the retrieved access token alongsided the requests (in an auth header for example). This one seems a bit more tricky. Given this context, I have a couple questions:...

Addition field not returned

I added a role field to the user schema but for some reason, it's not getting returned after calling the sign-in api endpoint. Here is my auth.ts. I know that I'm not supposed to add the role to the session conventionally but I did it so that I don't hit the database for role checks. I need the user sign-in endpoint to include the role field. `export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg",...

Issue with BetterFetch on vps

When running the app on vercel everything seems to work But as soon as i switch over to my own vps i keep getting BetterFetch issues it seems.. ```Error fetching session: Error: fetch failed at context.fetch (/app/node_modules/next/dist/server/web/sandbox/context.js:322:60)...

Offline `useSession`

Hi! Are there any good practices on offline support? So far my research led me to use JWT plugin, so I can store the token in the local storage and verify if it has not expired yet. But using useSession always calls the API Should I just create custom react provider and serve my decoded from token user or can any library api from better auth be used? Thanks!...

Error: hex string expected

Hi, I have an error when logging in, even though I think I've configured everything correctly. Here are some ss I'm a newbie, so I'm probably missing something. ...
No description

How to force the user to create an organization?

In my system, every user must have an organization. There will always be only one. I want the user to be required to create the organization right after being created. And whenever they log in, that organization should already be set as the user's organization.

Activating 2FA only for users with admin role/permission

I have several roles in our product. Is it possible to only active 2FA for admins?