Better Auth

BA

Better Auth

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

Join

bug-reports

help

polar db schema

hey all- when im using polar.sh should the npx @better-auth/cli generate also add to my schemas the link between orgs / users or do i need to do this manually. i remeber stripe plugin added it to the schema generation?...

Dynamic Access Control hasPermission is always false

Hi guys, I am very likely doing something wrong, but I've been looking everywhere for a little more information and can't really find anything. I have enabled the organizatoin plugin and the dynamic access control, and have been able to successfully create a role. The role is in the database, it looks good, i assigned it to a user, and that also looks good. But whatever call I make from that users session, checking for a permission always returns false. Simplified Example:...

Are default roles wiped out when defining a new one?

I'm using the admin plugin, and I wished to add one extra additional role to the defaults. I wish to keep user/admin as-is. ```typescript plugins: [ admin({...

Issue re-signing in with Google after logout

Hi everyone, I’m having an issue with the Google login. The first time a user signs in with Google, everything works perfectly the account gets created, cookies are set, and the redirect works. But after logging out and trying to sign in again with the same Google account, I get this error: SERVER_ERROR: [TypeError: Cannot read properties of undefined (reading 'accountId')] It happens right after Google redirects back to /api/auth/callback/google. It looks like Better Auth is trying to link the account again, but accountId ends up being undefined. If I delete the record from the accounts table and try again, it works fine, but once I log out and re-login, the same error comes back....
No description

Session has different userIds in Session Object and User Object after login into an active session

If I log a user out and back in again, it can happen that the session object in the session contains a different user ID than the user object in the session.
Am i doing something wrong? I use drizzle and planetscale MySQL as my database....

Reset password query

I don’t want the password reset form to appear if the reset link has already been used. Instead, I’d like to show an “expired link” message. Similar to how email verification redirects to a callback URL, is there a built-in way to handle this for password reset? I solved it with a custom plugin, but I’m curious if I’m missing an existing solution. Any help would be appreciated.

Betterauth Stripe Error

I'm getting this error from the Betterauth Stripe plugin and had search for the available information in the docs but could not find one that will help me out. I'm expecting Betterauth will handle the plan upgrade when user already subscribe to a plan and want to go for the higher tier. Here's the error: BetterAuth subscription upgrade error: Object { message: "This subscription cannot be updated because the subscription update feature in the portal configuration is disabled.", status: 400, statusText: "BAD_REQUEST" } webpack.js:1:14352 ...

Better Auth CLI Not Detecting Admin Plugin Schema Changes

I'm having an issue with @better-auth/cli generate not updating my Drizzle schema when I add the admin plugin. I have the admin plugin configured in my auth setup: plugins: [admin()] When I run npx @better-auth/cli generate, it doesn't add the expected fields (role, banned, banReason, etc.) to my existing schema at ./src/lib/server/auth-schema.ts....

How do i redirect to a specific provider login within Next.js Middleware

I'm trying: ```ts import { type NextRequest, NextResponse } from "next/server"; import { headers } from "next/headers";...

after updating backup codes using generateBackupCodes it gives json parse error

it should give backup codes as it was giving before updating backup codes but giving error instead POST /api/auth/two-factor/generate-backup-codes 200 in 5423ms ⨯ SyntaxError: Unexpected number in JSON at position 1 (line 1 column 2) at JSON.parse () at async page (src\app(settings)\settings\security\backup-codes\page.tsx:33:15) 31 | }...

Having issues with Enterprise SSO Registration using PingFed

So I'm following the documentation on how to register an OIDC Provider https://www.better-auth.com/docs/plugins/sso, but for some reason typescript doesn't recognize oidcConfig as a value to whatever the type is in the parameter. Is the documentation outdated? I updated to the latest version yesterday and I'm still having issues.
No description

Drizzle migration error

Whenever i try running drizzle-kit push, I get hit with the same error: error: column "id" is in a primary key Using Postgres...

Keep auth state (server & client) in sync with path-based workspace in Next.js

Context • Our app uses a path segment for the workspace slug: /w/<slug>. • A middleware ensures the session’s active organization matches the path: ```ts if (workspace.slug !== slug) {...

Usage base plan

@Better Auth its there any plugin our integration to create a paid user with usage based instead of only a plan?

Fetch user invitations

Is there a function for list all the invitations for a user from the client without specify the organizationId? At the moment an active organization seems required, but i would like to fetch all the invitations from all the organizations for the user...
Solution:
Its works fine, there was a problem in my setup

getSessionCookie and getCookieCache always null

I'm having issue with middleware and getSessionCookie in next15 Here's my middleware.ts: ```ts import { getCookieCache, getSessionCookie } from 'better-auth/cookies';...

Access to fetch at 'https://www.feeldesign.ai......' from origin 'https://feeldesign.ai' has been bl

I am getting CORS error "Access to fetch at 'https://www.feeldesign.ai/api/auth/sign-in/email' from origin 'https://feeldesign.ai' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." although I have configured trustedOrigins for both in auth.ts and auth-client.ts. How to solve it? I am using NextJs export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_BASE_URL,...

Session is null in Nextjs 15 middleware (Express backend) only in prod

Hi guys, I am able to get session in middleware with nodejs runtime in my dev server, but when I deploy in production it doesn't seem to pass any cookies when I make the request to the expressjs auth server.. What is the issue? Here's my middleware.ts ```ts...
Solution:
So I managed to solve this issue. Problem was I was using cross subdomains (different subdomain in frontend and backend). Emphasis on crossSubDomainCookies and defaultCookieAttributes

Issue with better-auth v1.3.27 infering values

I have a better-auth instance with a custom session plugin. My code it was working well on the previous version v1.2.27. I had some errors with a 422 error so I upgraded the version. After the upgrade I started to get an issue with the createAuth method. I needed that method to let the backend and frontend have the types of the context. How I can address this issue? As far as I know a fix it could be to use the original better-auth type:...
No description