Better Auth

BA

Better Auth

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

Join

bug-reports

help

How do you make fetch call from Nextjs to Hono with auth ?

I am not sure if this is the right way to fetch with auth , did not find any docs related to this , normal fetch call i did not how to pass the auth. With this i am getting data:unknown and a 401 error....
Solution:
When you have an entirely seperate Nextjs frontend and Hono backend , to make an authenticated request ```ts const res = await fetch("http://localhost:5000/api/profile", { credentials: "include",...
No description

2FA Error

await authClient.twoFactor.verifyTotp({
code: "" // user input
})
await authClient.twoFactor.verifyTotp({
code: "" // user input
})
...

Problems with useSession hook

Hey so I have this application where the backend is in ASP and I have it protected where I have to use the full JWT by better-auth to authenticate to the backend. I have created a tanstack query that fetches that token, but the problem is that sometimes despite being authenticated the provided token to get the full one gotten through the data object provided by the useSession hook is null and I get errors when trying to get it, but in the end I get it because the tanstack query retries and gets it eventually. Its a problem for the profile page, because the placeholder data for the fields is gotten from the session and on the first renders of the page it is empty. Has anyone dealt with this problem before? If so how did you manage to fix it? Here is how I get the data for the profile page for example: ```...

findUserRoles Customizing Session Response

Could you please help me with an example to understand how would be the findUserRoles method to be able to customize the session in betterauth https://www.better-auth.com/docs/concepts/session-management#customizing-session-response:next:...
No description

Nextjs Frontend + Express Backend (Better-auth @express), Better-not triggering custom adapter

Hi. I'm using Nextjs frontend and express backend for a project. The better-auth is implemented at expressjs. The backend is a microservice comprised of many different service. the auth service provides the jwt token which the api-gateway verifies to get the iss (issuer) and acl groups involved and only grants access to certain part of requests made by the frontend. currently I'm facing issue with implementing better-auth at both nextjs and express. I switched to better-auth to get the flexibility to add plugin type auths to my app. Here's the problem 1. The better-auth client (in Nextjs frontend) is configured to hit the express auth-service (backend running at som port) 2. the better-auth client is configured (baseURL) to hit the
backendurl:port/auth
backendurl:port/auth
. Here's a snapshot of the request hitting the backend. 3. The backend api-gateway receives the request and routes to the auth-service successfully. ...
No description

Cookies not setting in turborepo project

Issue: Cookies not setting in turborepo project Hey folks, I'm running into an issue with setting cookies in a turborepo setup. Project structure:...

Svelte Kit hooks.server.ts getSession not working

I want to use better-auth with SvelteKit, but I don't use the svelteKitHandler.. I've set-up a custom route apps/frontend/src/routes/api/auth/[...all]/+server.ts with the following code: ``` import type { RequestHandler } from "./$types"; // const ORPC_ENDPOINT = import.meta.env.VITE_ORPC_ENDPOINT...

Switching from Auth0 with nextjs and express backend

Hello, in one of my projects I am currently using auth0. From the frontend I need to make authenticated requests to my backend, which auth0 has a easy to integrate sdk for my express backend so i can do it fairly easily. I was wondering how would I go about doing this with Better Auth. Searched a bit but couldnt find a resource on this.

how to update the session

So I am quite new to better auth; earlier, next auth used to be my go-to solution, but it's getting rough. I am struggling to understand the designs of better auth. When I use getSession, the session is an object of session and user. ``` const {data: session} = authClient.useSession(); ?^ session: {...

unable_to_create_user error

I just try to create a user with Github using prisma and i got this error , my shcema is good and relation with db as well .
No description

Inferring additional fields on hooks

The additional field role is not found inside the databasehooks. I ran better-auth/cli generate and prisma migrate as you can see the screenshot from the prisma studio , the user table have that column. I also tried restarting the TS server on vscode which did not solve the issue...
Solution:
Hey guys ( @aswnss, @Rufis ), this is a known limitation of Better-auth. However I do have a PR which fixes this. Once merged your issue will be resolved. You can track the PR here: https://github.com/better-auth/better-auth/pull/2158...
No description

use `updateUser` in route handler

yo so ik u use authClient on client side but if i want to Update User Information on server side (from a route handler) what do i do? docs show `await authClient.updateUser({...
Solution:
And for server from your auth.ts

Drizzle + Better Auth -- No changes, password auth fails?

Better-Auth Ver. 1.2.7, Drizzle-Orm Ver. 0.41.0 PostgresError: password authentication failed for user.
Checked supabase status and everything working as expected.
...
Solution:
Rebuilt app building up pages and components with latest everything, and works again.

2FA getting error generating totp uri

I have 2fa enable, and when i trying to sign in, i'm getting error generating totp uri. I'm getting 401 Unauthorized. I double checked the password. I'm using sveltekit. here the snippet i used directly for docs ```typescript...

Can I delete/remove the default "user" role when using admin()

I don't really need this role, so wondering if I can delete it?
Solution:
I don't think so, unfortunately.

auth.api.getSession() returns unknown for user and session

Package: better-auth@1.2.8 I'm using better-auth with Drizzle ORM, and although the system works correctly at runtime, the types I get from auth.api.getSession() are not as expected. The inferred type is:...

Issue with OIDC Consent Page

I have a really weird behavior trying to use the BetterAuth OIDC client. I have a really simple setup as described in the docs, but when using ```tsx const { error, data } = await signIn.email(...

BetterAuth with custom Nextjs basePath

Hi everyone! I'm working on a project that's hosted on a subdomain of a website, so I had to set a custom basePath in my Next.js configuration. Now I'm having trouble getting BetterAuth to work properly with this setup. I adjusted the basePath for the authClient, and the best result I got was a POST request being sent to: ...

Multiple emails?

There was any solution or plugin to allow multiple emails will be linked to user and used in social connections as well?

Drizzle generate creates default values as variables instead of strings

In the code below the default values for status in invitation and role for member ( member and pending) should be strings but are generated as variables. ```ts export const member = pgTable("member", { id: text('id').primaryKey(),...