Better Auth

BA

Better Auth

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

Join

bug-reports

help

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?

Stripe subscription management

Hi, I tried to setup stripe, it seems to work, but when I try to upgrade a user to a subscription, next.js says this: POST /api/auth/subscription/upgrade 404 in 76ms do I have to write the route myself or is it automatic? I really don't know...

After successive transactions, it throws you to the login page

It is very interesting, I think it is related to the rate-limit. When I try to make a transaction in a row, I am redirected to the login page, but since the user has a session, the login page does not work properly, and when I return to the homepage, I appear to be logged in.

Basic Authentication with Caddy

I serve my app with Caddy and I have a set Basic Authentication in my Caddyfile : ``` example.com { basic_auth { # Username "Bob", password "hiccup"...
Solution:
To get around, I changed replaced my env variable from BETTER_AUTH_URL=https://example.com to BETTER_AUTH_URL=http://localhost:3000 And I added trustedOrigins: ['https://example.com'] in my betterAuth config (auth.ts) Is this good practice?...

Is there an expiration of the email verification token?

I need to determine whether the email verification token expires. If it does, I plan to create a dedicated "Account Confirmation" page that indicates when the token has expired and displays a "Resend activation link" button. Additionally, I want to know the duration (in hours) for which the token is valid and how to capture an error if the token has expired.
Solution:
if the token is invalid, it just returns 401 instead

Admin Role

Hello, how can i manually set a user role ( Like example admin - In the database ) ?
Solution:
Yeah it is in the dtb

How to return error from sendVerificationEmail ?

Hi, How do I throw an error in this callback in betterAuth config ? I technically can throw an error but it's not handled properly on the client . Just want to setup a ratelimit which would work in emailVerification for calls from the server not only direct calls from the client....

Passkey Failed to verify authentication

Hi, I am facing an issue where my password manager prompts me to use passkey when page use Conditional UI. Error: Unexpected authentication response challenge "AB", expected "AA" ...

inferring types on the client, based on plugins added on the server

I have a monorepo, with the admin plugin added to the server initialization of betterAuth. I was expecting the additional user properties, like role would be accessible from session.user. Here's my server code: ```ts export const auth = betterAuth({...