Better Auth

BA

Better Auth

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

Join

bug-reports

help

Cookies not being set on Vercel (works on localhost)

Hi! I have a Turborepo application and it works perfectly on localhost, but on Vercel the cookie is not being set. `apps/web apps/api ...

Any idea on how to implement suspicious login detection?

I was thinking on using the database hook on session creation but if there is any other way that is better then please let me know

organizationId gives an error when passing to getFullOrganization() function

I have a SvelteKit project. I believe I have set up everything as in the docs. The create organization function works as does the get active organization function, but getFullOrganization function is not working. Any help appreciated!
No description

Update user with additional fields

I've defined additional fields on my User struct ```ts additionalFields: { description: {...

Cannot use `after` hook to create a plugin with hono.

Hi, I'm trying to build a plugin for myself and whenever I use an after hook, I get the following error:
# SERVER_ERROR: Error: TypeError: Cannot read properties of undefined ( reading 'reloadNavigation')
# SERVER_ERROR: Error: TypeError: Cannot read properties of undefined ( reading 'reloadNavigation')
...

Infinite Redirect - NextJS

Hey, I am having an issue when my DB is reset during development that I am not ever able to clear the now invalid cookies. Obviously this in general should never be an issue but if it does happen then the only way for a end user to recover is by manually deleting their cookies which is unreasonable. (This could happen in production if a user clears all their sessions for example.) In my middleware I am using getSessionCookie(), which for this situation will return true. Then in my server component I am calling, await auth.api.getSession({...
Solution:
The issue seemed to be with trying to redirect in the page rather than letting my middleware handle that, I am guessing the redirect hijacked the response from the auth call which would have caused the clearing of cookies.

Defining after hook matcher produces error related to node internals.

Hi, I'm trying to build a plugin for myself and while I try to add an after hook like so: ```typescript return { id: "ungabunga", hooks : {...

Can I store the better auth authentication data in multiple database

I want to use 3 separate database to store things I am using Hono + Drizzle + Postgress ``` Use separate databases...

can't get session after verify magic link token

``` React.useEffect(() => { const handleTokenVerification = async (token: string) => { const { error, data } = await verifyToken(token); ...

Google OAuth redirect is going to backend homepage instead of frontend after login.

I have a NestJS backend and TanStack Router in the frontend. Email and password login is working fine, but Google Sign-In redirects to the backend homepage after login. How can I fix this

Resolving Discord ID during flow

I'm using BetterAuth as my Oauth handler. What I want to be able to do is extract the authorised users Discord Snowflake User ID during the process to save to my database (prisma). After some digging, I never see that value get exposed....

Get password updatedAt

Is there a way to retrieve the updatedAt field from the account table when the password has been updated from the client side ?

Next.js Middleware config

how to setup better-auth middleware with next-intl middleware https://next-intl.dev/docs/routing/middleware

Magic link invalid url and baseURL issue

When I try to generate a magic link, I get this error: ```js Magic link error: TypeError: Invalid URL at new URL (node:internal/url:818:25)...
Solution:
Fixed it: Issue was because it was behind a proxy it recieved http instead of https
No description

HELP!! Cause of third-party cookie blocked, I've tried to use Token instead of Cookies, but...

FrontEnd: React BackEnd: Express //auth-client.ts import { createAuthClient } from "better-auth/react";...

Confused on adding custom roles

Hello! Apologies if this has been answered elsewhere. I've searched through these forums and haven't found a thing, though. I have, in fact, read the docs! Also searched on Google, didn't find a thing. I'm using Next.js, React, better-auth, a few other plugins, all latest version. I'm trying to give someone, say, the "Member" role, or "Admin" (capitalized A). However, when I try to do this (clientside, on a webpage): ...

Google OAuth redirect is going to backend homepage instead of frontend after login.

I have a NestJS backend and TanStack Router in the frontend. Email and password login is working fine, but Google Sign-In redirects to the backend homepage after login. How can I fix this?

MCP Oauth how to show consent screen

When using th emcp setup acording to the docs oauth get directly the logged in user without asking him for consent when adding the MCP server to Claude Desktop for example. How can a consent screen similar to Vercer MCP server be added?...

How to mock better-auth with MSW?

I tried to use MSW to mock the (GitHub) OAuth flow. However, I have been unsuccessful in getting the session on the server. Here is a minimal reproduction: https://codesandbox.io/p/devbox/better-auth-with-msw-5dy86g ...
No description

OIDC Plugin + Organization Plugin for limiting user OAuth to specific organizations tied to an app

I may have missed this in the documentation, but is there a way for me to combine the OIDC plugin with the Organizations plugin such that when a user tries to authenticate into a specific application, we check that user's membership with an associated organization during the OAuth process, and if the user doesn't have a membership, then authentication into that app should be denied. Basically, I am making an auth-gateway system to where my team can internally tie different applications (and OAuth configs) to different end customers (better-auth organizations plugin) via an administration portal. My team will deploy a client-application that users log into by OIDC, pointed to the auth-gateway application we have setup (both NextJS apps will use better-auth, with auth-gateway being the source of truth and client-application pointing to our auth-gateway with it's configured credentials. In other plugins, I see the ability to add custom fields and callbacks/validators on the actions, but from what I can tell, I can't do that for the OIDC provider plugin....