Better Auth

BA

Better Auth

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

Join

bug-reports

help

Best way to protect routes in TanStack Start?

What's the best way to protect all private routes like /dashboard*, so they redirect to /login if no session exists? I don't see this aspect in the example: https://github.com/better-auth/better-auth/tree/main/examples/tanstack-example Below is my attempt, but session is always null, even if the user is authenticated. ```ts...

elysia with better auth not working

Hi, it seems that the integration is not working correctly, i set up everything (i hope correctly) but one i start running elysia server i get script "dev" was terminated by signal SIGABRT Could be a problem related to bun? the server runs if i remove betterAuthView...
No description

Google auth redirecting to the main site instead of the webpage

I have an issue which I am not experiencing on other projects using better-auth I have http://localhost:8000 set as BASE_URL under process.env.BETTER_AUTH_URL, which is my Express API where http://localhost:3000 is my Next.js website ...

Help with Email + Phone before 2FA Flow

Hello, At work we require to implement auth for login and I would like to use BetterAuth for it if possible The requirements are that we signup with email password, then we enter phone number and verify it with OTP, then we enable 2FA....

Refresh Spotify access token

I'm basically getting the access token from the db on the server to make calls to the spotify api but the token doesn't automatically gets refreshed only when I sign in and out on my frontend Is there a way to refresh the token automatically or do I need to figure out how to do it manually?...

Social login Account creation with additional field

How to pass additional state during a social provider sign-in (e.g., Google). When a new user signs up with say for example Google, I want to store an extra field in the database, like { "a": "123" }, alongside the default user data. How can I pass this custom data from the client and handle it on the server to save it in the DB? ``` const signIn = async () => { await auth.signIn.social({ provider: "google", loginHint: "EXPERT",...

Social login with separate backend domain

If my frontend is at a different domain than my backend, the cookie from the 302 redirect doesn't get set. If using bearer tokens there's no opportunity to get the token from the request before the redirect occurs. Email/password works.

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();...

FAILED_TO_CREATE_USER

How can I debug, whats going on? I dont see anything in console
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...

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

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
Next