Better Auth

BA

Better Auth

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

Join

bug-reports

help

useSession is not is not callable ?

need help with the clients hooks every client hook gives me a typescript error like this `` This expression is not callable. No constituent of type 'Atom<{ data: { session: { userAgent: string | null | undefined; id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; }; user: { ...; }; } | null; error: BetterFetchError | null; isPending: boolean; }>' is callable.ts(2349)...
Solution:
My guess is your auth client is importing createAuthClient from better-auth/client rather than better-auth/react

Error on generate schema with prisma

```bash npx @better-auth/cli@latest generate 2025-04-10T01:52:48.957Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. at new PrismaClient (/Users/filliperibeiro/Desktop/www/pessoal/structura/node_modules/.prisma/client/default.js:43:11) at /Users/filliperibeiro/Desktop/www/pessoal/structura/lib/auth.ts:5:16...
No description

How to make two unique fields in a schema

So I'm trying to make a plugin with many to many relationship. I want it to have teamId and branchId columns. the combination of teamId & branchId must be unqiue, how can I achieve that? ```ts schema: { teamOnBranch: { fields: {...
No description

How do I use the auth.api.deleteUser endpoint from a server action?

I am trying to figure out how to invoke different auth.api endpoints from my server code in NextJS. I cannot seem to figure out what the implementation should be.

account_not_linked: I have react and express setup and using better auth

How to get this error to the frontend, right now it renders the better-auth error page

cloudflare + better-auth and turso

How to setup this in cloudflare any idea
No description

User avatars/profile pics for Microsoft Entra social sign in

Hello, I am trying to implement social sign in with Microsoft Entra. In the Entra dashboard my App Registration has selected User.Read and User.ReadBasic.All (the latter gives "Allows the app to read a basic set of profile properties of other users in your organization on your behalf. Includes display name, first and last name, email address and photo.") My better auth config lists the User.ReadBasic.All scope:...
Solution:
So I've partially solved it. I've confirmed scope: ["User.ReadBasic.All"] is correct, but the image doesn't provide the placeholder you see in microsoft apps if an avatar isn't explicitly set.

Determine if new user without callbacks in expo

When using authClient.signin.social in an expo app the deep link callbacks don't currently work, sounds like it should be fixed in an upcoming version. In the meantime I'm using the workaround that is in the example expo project to force a redirect after authenticating: ``` useEffect(() => { if (isAuthenticated) {...

Custom values into `authClient.signIn.social()`?

Hey there 👋 What's the best way to manually set user values when signing a user in through an OAuth provider? For example, I may want to set a custom, default user image instead of using your social provider image, or I may want a custom name or username. Since I am using Next.js, intercepting the user with a layout function is pretty trivial, but maybe there is some Better-Auth way to do this through hooks or something similar?
Solution:
you can actually map the value here for example ``` socialProviders: { google: { clientId: "YOUR_GOOGLE_CLIENT_ID",...

Update additional fields in updateUser

Can additional fields added in the auth instance be updated using the updateUser method?
Solution:
yeah you can.

additional fields not included in session

The role is included in the session object, but not the onboardingDone. The fieldName is the same as that in the database...
Solution:
If you're using an ORM, try removing the fieldName prop from the additional fields
No description

2025-04-09T13:12:33.351Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [AggregateError: ]

I'm getting this error:
2025-04-09T13:12:33.351Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [AggregateError: ] { code: 'ETIMEDOUT' }
2025-04-09T13:12:33.351Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [AggregateError: ] { code: 'ETIMEDOUT' }
...

The field "id" does not exist in the "verification" schema

Hey guys, I'm trying to get Better Auth working with Directus, a headless CMS system. I'm having to hack around a little by manually creating the tables that there isn't an analog in Directus, and am having an issue with the verification table, which outputs
# SERVER_ERROR: [BetterAuthError: The field "id" does not exist in the "verification" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".] {
cause: undefined
}
# SERVER_ERROR: [BetterAuthError: The field "id" does not exist in the "verification" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".] {
cause: undefined
}
...

typescript not recognizing role field in astro locals with better auth

added a role field via additionalFields in auth.ts. At runtime, isAuthed.user from auth.api.getSession correctly includes role, but TypeScript doesn’t recognize it on Astro.locals.user. My env.d.ts uses import("better-auth").User, which lacks custom fields. Tried inferAdditionalFields<typeof auth>() on the client, but it didn’t help Astro’s types. Any advice on aligning the types properly?

onAPIError not working

Hello, When i use onAPIError in the auth config and try to log the error there is no logs in the console. Is there a way to use it ? I followed the docs...

Admin API tools (without authentication)

Hey guys, quick question i couldn't find the answer to in the docs: I want to get an instance of the admin client that doesn't require authentication, so I can have a CLI to manage users. I.e creating users / setting passwords etc. Or i just need access to the underlying logic that better-auth uses to CRUD users ...

"userId" as id of user instead of "id"

I want to implement BetterAuth inside an existing application, but the user model has user.userId field as the id, but I see BetterAuth requires it to be user.id is it possible to change this or should I make an additional column for the better auth id?...
Solution:
We don't allow custom id names yet. @IceeCold It may be a future we add later down the line however....

set cookie manually in next.js server action

```ts "use server"; import { auth } from "@/auth"; import { cookies } from "next/headers";...
Solution:
okay figured it out I needed to use decodeURIComponent on the value...

stripe subscription edge case question cancel_at_period_end

Hi, I'm working in SvelteKit with the new Stripe plugin and drizzle adapter. All is smooth but I'm testing edge cases where a customer subscribes, cancels and resubscribes. the "cancel_at_period_end" doesn't change to false or null after the resubscription. Is onSubscriptionUpdate hook the best bet? I haven't gotten this to work if so: onSubscriptionComplete: async ({ subscription: subscriptionData }) => {
await db...

Difference between SSO and social sign on

What's the difference between SSO and social sign on? Why do I need to register the SSO oidc provider in the database when I can configure social sign on through code? What is it doing when I call the register with the user account, is it somehow saying that user owns the oidc provider?