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() - expression not callable?

Hi guys, anyoen have any idea what this means? First time I've encountered it.
No description

127.0.0.1 oauth redirects

Hi all, I'm migrating from auth.js and trying to get one of my custom providers ported... The provider doesn't allow localhost as redirect URI's, instead opting for 127.0.0.1. When attempting to redirect to the authorization URL, I'm getting errors from the provider that the client is invalid (due to a localhost redirect URI). However, when I change it to the 127.0.0.1 address, I then get state mismatch errors when coming back from the auth flow. Is there a best-practice for dealing with this? ...

Latest CLI changes drizzle datetime fields from mode: 'timestamp' → mode: 'timestamp_ms'

@Better Auth i’m using drizzle + cloudflare D1 and i added some user.additionalFields to my config, so i ran npx @better-auth/cli generate and all the existing datetime fields were changed from a unix timestamp in seconds to a unix timestamp in milliseconds. here’s a representative example extracted from session, with before:
expiresAt: integer('expires_at', { mode: 'timestamp' }).notNull(),
expiresAt: integer('expires_at', { mode: 'timestamp' }).notNull(),
...

A Node.js api is used which is not supported in the edge runtime

Using better auth I get this error: $ next build ▲ Next.js 15.3.3 - Environments: .env.local ...

Hey

I need to automaticly update username for google social connection when user is signing in / registering for the first time. any ideas how do to so
Solution:
you mean manually, you can use mapProfileToUser method https://www.better-auth.com/docs/concepts/oauth#mapprofiletouser...

Enforce Email Domain Restriction on Google

How can I achieve this? I tried doing the example from the documentation (https://www.better-auth.com/docs/concepts/hooks#example-enforce-email-domain-restriction) but that did not work for my case. I am trying to restrict for only a specific domain "example.com" to be accepted to sign up. Thank you!...

Is there a way to pass a transaction (tx) into Better Auth APIs?

I’d like to create a custom signup flow without relying on the built-in beforeSignUp or afterSignUp hooks. I want to build a separate API endpoint so that I can fully customize the request and response structure. My goal is to perform some custom database operations (for example, creating basic data) before calling the Better Auth signup logic — and wrap everything inside a single transaction for consistency. ...

SvelteKit Issues

Hi, I've been following the SvelteKit guide and I am unable to get the session on the client side. server auth ``` export const auth = betterAuth({...
Solution:
After looking it into, I realised the issue was that I was running my server on another machine. If you have a similar workflow, you have to set the url to the local IP of the machine that is running the server. Make sure to add the trustedDomains and baseURL parameters

Adding users to Team when accepting an Invite

Hi! Has anyone looked into having users added to Teams when they accept an Invite? My desired flow requires that I define a members Team memberships before sending out the invitation. So I would enter the new users email, along which teams it belongs to. My current idea is that I will have a custom request to my backend, were I save the teams in a database and then have a afterAddMember hook that will add the new member to each of the Teams specified...

session cookie name

Is there a way change the name of the httponly cookie sent to the client?
No description

After login not getting the activeOrganizationId

After creating a new account I redirect the User to an onboarding path. After this a org will be created or joined. I can see activeOrganizationId in the browser dev tools. But after a logout and login the User gets again redirected to the onboarding. I can see the session but activeOrganizationId = null....
Solution:
yea that's normal behaviour, from what ik, use the database hook to get the user organization (you can also save it in the db as lastActiveOrgId for example) before the session is created in the database (check image for example)

Best practice to deal with a "child profile" / "kid profile"

Hi team, I was reading the account & organization sections, but I may need some guidance in order to fully understand the best concept to follow. Goal:...

SSO/SAML Example

i'm pretty new to nextjs/better-auth and wondering if anyone has any sso/saml examples on github yet for me to look at I'm having issues with even getting a curl to work with the default SSO provider. always end up with {"code":"NO_PROVIDER_FOUND_FOR_THE_ISSUER","message":"No provider found for the issuer"}...

Schema adjustment not being reflected.

Hi guys, I'm hoping someone may be able to give me hand with this, I'm 90% confident I'm missing an extra step here or something. I have a /schemas/ folder, with multiple different files and an entry index.ts which exports * from the different files....
No description

Multi Step Authentication Flow

hello, I’d like to implement a multi-step authentication flow. My use cases include: A combined sign in / create account page that, after collecting the email, redirects to: Sign in (collect password, then possibly 2FA)...

Better Auth implementation with Next.js with my current backend setup

Hi everyone, I already have a custom backend with working auth APIs: POST /api/auth/login → expects { email, password } (or sometimes { phone, password }) and returns an access_token....

Issues with expo plugin on android

Hello, I've been using better-auth with expo on ios very successfully on production for the last several months. I recently started using it on android as well, but I'm seeing a weird behavior that does not happen on iOS. I have a provider that wraps the better-auth hooks, with the following code: ```...

Error Changing user email in server from client (URGENT) EXPRESS JS

when i invoke change email from my client const UpdateEmail = await axios.post("/api/auth/change-email", { newEmail:values.email }, { withCredentials:true ,baseURL:process.env.NEXT_PUBLIC_SERVER_URL}); ...

Trying to resend verification email

I can't see anything in the documentation relating to how to re-send a verification email if the token has expired. I try using the authClient.sendVerificationEmail({ email: "theuser@where-ever.com", callbackURL: "/dashboard"}) and I get the following; "YOU_CAN_ONLY_SEND_A_VERIFICATION_EMAIL_TO_AN_UNVERIFIED_EMAIL" The email IS unverified in the database so I seem to be a bit stuck... Also, I know the email is unverified because it's an account I'm testing and I haven't verified it......

Connecting toNuxt to a 3rd Party API

We are currently in the process of speccing a Nuxt application to replace an aging Vue application. The two requirements that we have set in stone at this point are: 1) Authenticate Users against MSAL, and 2) access our in-house API server (Hapi) using the MS Access Token What we are trying to figure out is how we store/manage the tokens once we have connected to Microsoft. We have managed to get the appropriate tokens from MSAL (usting nuxt-auth-utils) and atached them as Bearer tokens using an api plugin. We just need to figure out how and when to refresh the tokens ...