Better Auth

BA

Better Auth

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

Join

bug-reports

help

New sessions keep expiring after only 1 day, despite config being set to 7 days

Hi, I created a Next.js project with better-auth recently, but I keep running into a problem: every time I create a new session by signing-in, the session expires after only 1 day. I'm not sure why this is happening, it happens even if I specify 7 days for the expiresIn property under session. Attached is a screenshot of what the session looks like in my database and below is my config file. Does anyone have any thoughts why this is happening?...
No description

OAuth Proxy while using Cloudflare

Figured I'd put this here cause there may be others with similar issues. Quick summary of the whole stack: - Express backend locked down with CORS, related origins added, running behind Cloudflare. OAuth proxy url installed with the specific current and production urls set....

How do I make username a required field during sign up?

// auth.ts ```ts export const auth = betterAuth({ appName: 'appname',...

afterUpdate hook receives query result instead of account object

I’m using better-auth@1.3.26 with the drizzle adapter and neon-http setup. The account.update.after hook receives a query result object instead of the updated account. Expected:...

genericOAuth link with other additional field

I’m using genericOAuth for login, but my provider doesn’t return an email — it only provides a phone number or other field. I need to link the logged-in user with an existing account in my database using this phone number. How can I achieve that?

Admin plugin types doesn't work

Hi, do you guys any idea why I can use role from admin plugin but in code it shows me an error that the property doesn't exists? https://discord.com/channels/1288403910284935179/1427790036828553347

adding additional fields to accounts table

Hello, Is it possible to add a social handle field to my accounts table? Essentially what im looking for is the ability to store the users social handle in the accounts table. When using linkSocial it makes a row in the account table but it doesnt include any information about the users linkedSocial, how could I add this field? I had a look into the additionalFields docs but it doesn't look like this works with linkSocial function?...

Best way to setup server with multiple apps that need auth.

My server serves two separate desktop apps with the same api and auth setup currently. I have a solution in the after hook that gets the 'location' header and runs a deeplink redirect to the corresponding app, this location value is onconsistent with Twitch oauth if the user isnt properly redirected to my browser. I tried creating separate better auth handlers for each app, but im running into state_mismatch errors trying to sign in

obtaining the accountId which the user linked

Hello, I'd like to add some functionality into my app which when a user links a new social account they will get redirected to /dashboard/feed/{newAccountId}. However, it doesn't seem possible that the account ID is able to be retrieved, I tried using the onSuccess callback, but the response data includes no information about the social that they just linked. Is there a work around for this? ```ts...

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. ...