Better Auth

BA

Better Auth

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

Join

bug-reports

help

Problem with OAuth (Google) using BetterAuth with Express for backend and Next.js Frontend

Hi! Does anyone know how to resolve this? It's Express on the backend and Next.js on the frontend. The error appears in Express after continuing the authentication with Google ``` SERVER_ERROR: SyntaxError: Expected ',' or '}' after property value in JSON at position 191 at JSON.parse (<anonymous>)...

How to debug addPasskey not working in Production (Vercel)?

Having configured the passkey plugin, I can add a passkey locally/development but not in production (Vercel). I'm using a simple button in NextJS to trigger adding a passkey: ``` const { data, error } = await authClient.passkey.addPasskey();...
Solution:
I managed to resolve this. I had the value for rpID wrongly configured. 🤦 It was set to api.mysite.com rather than mysite.com. A [Fido2Client] Error in the Chrome console alerted me to the issue....

FAILED_TO_CREATE_USER

How can I debug, whats going on? I dont see anything in console
Solution:
Usually we need name when signing up as well.
No description

perform action after successful email verification

using ionic/vue client with express.js backend i want to perform an action after successful email verification. a possible place would be databaseHooks.user.update.before but unfortunately the object passed to this method only contains the updated property, e.g. { emailVerified: true }, nothing else. ...

Manually create a session

Hi, for testing purposes I want to create a session in my own controller, and set the right cookies. Although, it seems like the sesison token has to be in a certain structure. Has anyone got a better idea on how I can implement this? The cookie names do match, I am using NextJS so I would need a backend approach to create the sessions. ```ts // Create or get the test user...
Solution:
hmm...you can fill it with those details - ```ts import { createRandomStringGenerator } from "@better-auth/utils/random"; import { createHMAC } from "@better-auth/utils/hmac";...

not getting rate limited

Hey folks I'm testing the rate limit functionality and here is my code https://mystb.in/56596703647e0db856 even though I'm making more than 2 signIn request in one minute I'm not getting rate limited or any other error also please check if I'm handling the auth error correctly

Password not updating on resetPassword

Hi, I have been trying out better-auth with Elysia + SurrealDB (W/ Featured Community Adapter on Better Auth Site) + SvelteKit (SSG-only) and so far everything has worked out but I have started to face a weird issue related to the forget/reset password flow that I haven't been able to exactly pin down. I have been able to reach at the point where I am able to redirect the user to a proper page to reset the password, where I have them fill out a form, which when submitted, calls ...
Solution:
for now i just built the patched package, added it to my application, and tried the flow, and it has worked correctly

Best way to run code after user logs in/out

Looking for the best way to run code after a user logs in/out of the app. I need all the users info from the DB obj, the same info that would be returned with authClient.useSession() on a page...

Query tables created by better auth with kysely

Hey, I just set up better-auth with kysely and I noticed that I cannot query the database users etc manually as my typescript thinks my db instance does not have the correct types and thinks these tables do not exist. An example of what I mean is attached as an image below, How do I get my kysely instance to allow me to query all the tables created by better-auth
No description

How to Force Email-OTP Plugin to Use Redis Instead of PostgreSQL

In my Next.js project, I'm using the email-otp plugin for authentication. The primary database is PostgreSQL, and Redis is set up as a secondary storage. I assumed that sessions and OTP verification would be handled through Redis. However, when attempting to send an OTP, I get this error: ```...

Image not updating when using genericOAuth client.oauth2.link

When I sign up a new user with client.signIn.oauth2 the user info I get from my OAuth provider contains a image parameter that goes into my user image field in my db. But when I try linking an existing user using client.oauth2.link the user info I get from my OAuth provider still contains a image parameter but that info never gets updated in my user image field in my db. https://www.better-auth.com/docs/plugins/generic-oauth#linking-oauth-accounts...

Unable to send OTP

When executing sendVerificationOTP i get an error, all versions are up to date (drizzle-kit, drizzle-orm, better-auth) ```typescript const response = await auth.api.sendVerificationOTP({ body: { email, type: 'sign-in' },...

SolidJS useSession hook - refetch

I'm trying to use the solidjs hook for the store of the useSession hook and got everything working in terms of loading user data in etc, only thing i want to to is force a refetch of the session and noticed when debugging there is a refetch method attached to the hook but it's not declared in the types ie
const session = authClient.useSession();
await session().refetch();
const session = authClient.useSession();
await session().refetch();
...
Solution:
yeah it's intended

Callback when logging in with social.

Hi guys, is there a way to listen for a callback when a user does a signup using a social platform? Thanks

deleteUser questions

Hi there I am facing issues with user deletion and I'm not sure if there is a bug or if I misunderstand the concept. https://www.better-auth.com/docs/concepts/users-accounts#delete-user...

Replace or override baseEndpoints

I want to replace the built in resetPassword endpoint ``` const authenticator = betterAuth({ plugins: [ {...

Change email for unverified user ?

Is there a way to change the email of a user that hasn't been verified ? For exemple this cover the case a user register miss type the email and want to change to his good one.

MSSQL not working at all

Hi, is anyone using BetterAuth with MSSQL via Kysely? Migrations run fine for me, I can see the tables getting created in the DB, there is only 1 other table in it. When trying to login, I get: SERVER_ERROR: The data types text and nvarchar are incompatible in the equal to operator. ...

activeOrganizationId is null, but user is in Org.

Hey, I tried to get the activeOrganizatuinId with ```typescript const session = await auth.api.getSession({ headers: await headers(),...
No description

Multiple roles per user in Admin plugin

Hello, I'm trying to create an app using NextJS. I'm using Better-Auth with the admin plugin which seems good enough for what I need. However, I want to be able to provide users with different roles, but having multiple roles, e.g. Accounts, Sales etc. Using just the Admin plugin, how can I assign multiple roles to a user. I don't really want to use the organisation plugin, as I don't need that complexity just for multiple roles. Thanks!...