Better Auth

BA

Better Auth

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

Join

bug-reports

help

Auth Client not sending cookies to Server

I'm using authClient.$fetch in a project to make requests to my server (Elysia + Better Auth). However, I noticed that the server is not able to identify the user, because $fetch is not sending the cookies in the request. I tested adding the cookies manually to the request, and it worked correctly. My question is: shouldn't authClient.$fetch include cookies automatically? If that’s not the expected behavior, what is the advantage of using it instead of the standard fetch?...

Bun: Failed to initialize database adapter

Hi, I'm using buns SQL with kysely-postgres-js' dialect like so: ```ts export const db = new Kysely<Database>({ dialect: new PostgresJSDialect({ postgres: new SQL(process.env.DATABASE_URL!, { adapter: "postgres" }),...

Proxied Google OAuth no longer setting cookies

Hello! I'm using TanStack React Start v1.132.34 and BetterAuth v1.3.26. I'm using Google OAuth with the OAuth proxy plugin to allow sign in on preview deploys hosted on a different domain from the prod site (deploy-preview--xyz.netlify.app vs main.site.com). This flow was working previously in BetterAuth v1.2.10, but after updating it seems to be have broken. Whenever I call getSession or useSession, I only get null if the request was proxied (so only the only working domain is the BETTER_AUTH_URL ). I've stepped through the requests in dev tools and found that the 302 response for oauth-proxy-callback does contain the set-cookie header with the expected values (__Secure-better-auth.state and __Secure-better-auth.session_token), but on the preview deploys the next request for get-session doesn't use it (its cookie header is set to only "__Secure-better-auth.state="). On the main site, this fetch does include the __Secure-better-auth.session_token, which returns the session properly. I've tried updating the cookie attribues to sameSite none and secure: true, which I see reflected in the oauth proxy request, but it doesn't seem to help. Have there been any other changes to cookies, OAuth, or proxying that could have broken this? Thanks!...

infer additional organization field on nextjs doesnt work for hooks?

my config : ```ts // CLIENT import { createAuthClient } from "better-auth/react"; import {...
No description

how to use organization plugin adapter

I'd like to use the organization adapter's method findMemberByOrgId. since it already exists I'd like to avoid writing the db query myself. https://github.com/better-auth/better-auth/blob/dd27fa9b7981e900fb59c317c1f4aed53c05e45a/packages/better-auth/src/plugins/organization/adapter.ts#L192 how to access it from user land?...

Best approach for handling two user types (CMS + App) with Better Auth and Prisma

Hey everyone! I’m currently building a project where I’ll have two separate frontends: A CMS for internal/admin users and A client app (for normal users) Both will use the same Express backend, and I’m using Better Auth for authentication together with Prisma and MongoDB. I want to keep the users separated.. for example:...

Organization Logic

How to handle logic to make sure that when user access layout in nextjs, its already have user and organization value? ```ts const headerList = await headers(); const session = await auth.api.getSession({ headers: headerList });...

Problems with infering client session from a monorepo

I have a monorepo using nextjs and hono. Since I don't want to have the better-auth config in the backend I created a package to handle all that part and import it from my client and my server instead of having an absolute path. So I created an method called createAuth which is going to build the authInstance to use it on the server and also it's going to return a type to use it on the client to infer that part. Since I updated to the v1.3.27 I started getting issues with the types so I have to remove the declaration: true prop from my auth package. That fixed the error that I had with TS but the session is not infered on the client....
No description

betterAuth + drizzle + pg throws error on `db push`

i'm getting: ``` PostgresError: foreign key constraint "account_user_id_user_id_fk" cannot be implemented at ErrorResponse (file:///Users/jackbisceglia/p/planar/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/src/connection.js:794:26) at handle (file:///Users/jackbisceglia/p/planar/node_modules/.pnpm/postgres@3.4.7/node_modules/postgres/src/connection.js:480:6)...

displaying error if account is already linked using linkSocial()

Hello, I am currently performing the below code on to link a social account to my user. Upon their return to my site I would like to check if the social they just linked was already linked to their account, this way I could show them an error saying "account xyz was already linked, please ensure to logout of your tiktok account if you want to link more." I have no idea how I am supposed to do this, because I have no control over knowing what account they are logged into on tiktok, until they complete the oauth flow, and I cannot use the returned value of linkSocial because they have to leave the page to go through the oauth flow. ...

email and password login, with unique username

Hey, is it possible to enforce unique usernames with email and password login? I want it to error if the username they chose is already taken, similar to how it works with emial. ```ts const response = await authClient.signUp.email({ email: data.email, password: data.password,...

Unable to initialize and generate schema.ts for sqlite with genericOauth plugin.

I'm setting up my nuxt project and I want to configure better-auth to use my companies Oauth2/OIDC provider to authenticate against with the genericOauth plugin. When running npx @better-auth/cli@latest generate --config ./server/utils/auth.ts the database gets created in the right place, but it's empty and no schema is generated (see error message below). Any idea what's wrong with my setup? Thank you and BR Simon This is my server/utils/auth.ts:...

`auth.api.getSession` returns null when headers from `auth.api.signInEmail` passed to it

I am trying to build a provisioning where I (SaaS provider) provisions an org and a user for a customer. I want to use better-auth-extended/app-invite (https://www.npmjs.com/package/@better-auth-extended/app-invite) for provisioning the user however that was not working after some debugging I found out that the session is being returned as null...
Solution:
i solved it by looking at the signInWithTestUser in test-utils https://github.com/better-auth/better-auth/blob/bcfd3c335cbbcee620499adca6592d86e8f4d933/packages/better-auth/src/test-utils/test-instance.ts#L236-L239 rather than passing userHeaders I changed it to ```...

Stripe Upgrade Issue

I'm having 2 plans Standard and Pro. Currently, I'm subscribed to Standard plan and want to upgrade the to the Pro plan Expectation: - When switched to Pro, the Standard plan will automatically cancel and will not recharge in the future. Actual:...

RDSDataAPI adapter is not working - error: [BetterAuthError: Failed to initialize database adapter]

I am trying to hook my better auth against an AWS RDS database using the RDS Data API, which is a supported dialect by Kysely. However, after manually running database migration and verifying database itself is connectable, I run into this error that is not very informative: [BettertAuthError: Failed to initialize database adapter]. I looked at my set-up and felt like I followed the right instructions. Here is my set-up below import { Kysely } from 'kysely'; import { DataApiDialect } from 'kysely-data-api'; import { RDSData } from '@aws-sdk/client-rds-data';...

Invitation + user creation

I'm struggling so hard to figure out a flow where an admin from an org can send an invite and within a single email sent the user be able to authenticate + accept the invite. This user is guaranteed to not have an account yet. how can I do this? isn't it a common enough flow? am I missing something here?...

Nuxt + Fastify integration guide

Hi, I'm trying to use better-auth with nuxt and fastify. First of all I need the apps to be separate as backend might in future need to work with many clients, not only one webapp. Now to the problem. The flow is like this. On the Nuxt side I've created authClient like this. ```ts export const authClient = createAuthClient({ baseURL: "http://localhost:3001",...

Any workaround for github issue?

Hi, does anybody have an idea if there is any way to fix incomplete AdditionalFields for organization as in the issue? https://github.com/better-auth/better-auth/issues/5234...

jwt setting multiple audience

we have three server one is api , one chat and one is signaling server for webrtc. chat and signaliing server uses socket.io but both are in different url and audience is different current audience in jwt allows only allow one audience string instead of array or there any other solutions for this or should i create an another endpoint for this with my own implement of jwt

How to refresh user/session data?

I'm having a hard time figuring out how to refresh the user/session data after the field values in the user schema gets updated. Scenario: When setting the email_verified to true/false in the database, the user object returned from still contains the old value of this field, making it confusing for the user to see if their email verification worked or not. The only way to update this is for the use to log out and back in, which isn't ideal of course....