Better Auth

BA

Better Auth

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

Join

bug-reports

help

Removing column

How can I remove this entire column as I am using firstName and lastName and I don't need it
No description

update additional field on user object via route handler

in my route handler, how can i update this additional value? is there a method in the api, or do i just update the document by querying mongodb: ```js...

Setup with different basePath?

How to setup Better-auth when I have a different NETXjs basepath, other than the base one? Like if I'm deploying my project in a subdomain of a main site, and have to change the basePath in next.config....

Better Auth with tRPC

is it good to wrap all better auth features into trpc? i mean like, i don't want to call authClient.signin directly, but i want to call it through trpc like const signInMutation = trpc.auth.signIn. so that all API calls are the same. because right now it's just auth it's a shame not to use trpc.

Set Client url for emailAndPassword reset

Hello! I'm using better-auth for node/express running on localhost:5001. I also have a react app running on localhost:3001. When I use the sendResetPassword better auth creates a valid token however with the wrong URL, using the server url I specified in baseBath. How can I specify the client url to use (in dev for example: localhost:3001)?
No description

Disable some of the default endpoints

is there a way to disable some of the default endpoints? for example i want to use all better-auth endpoints apart from the sign-up because i want to have a custom one....

Verify2FA Failed

```js const handle2FASubmit = async (e) => { e.preventDefault(); setLoading(true); try {...

help prisma error

i'm a beginner with better-auth i have an error for the signup and i don't know why even though the prisma schema is well defined. the password field is filled in correctly in the form Please can you help me to set up a login and signup...
No description

error: role "vscode" does not exist

``` vscode โžœ /workspaces/nethys/controlplane (master) $ bunx @better-auth/cli@latest generate โ ‹ preparing schema.../workspaces/nethys/node_modules/pg-pool/index.js:45 Error.captureStackTrace(err) ^...
Solution:
pass your db like this

TRPC help

Hello! I have a trpc.ts file that looks like:...

question regarding orgs and teams

does inviting to an org give them access to all teams if no specific teamid is specified and if not is this possible to do?

Checking permissions

I'm having some trouble understanding how hasPermission works. This is my code currently: ```ts import { createAccessControl } from 'better-auth/plugins/access'; import { defaultStatements, userAc } from 'better-auth/plugins/admin/access'; ...

OAuth with TikTok failing โ€” โ€œcode_challengeโ€ error on redirect

Hi! Iโ€™m integrating BetterAuth in my Next.js app with a custom PostgreSQL schema via Prisma. Everything works fine locally, but when I try to sign in with the TikTok provider on my deployed Vercel app, Iโ€™m redirected to a TikTok error page saying: โ€œAn error occurred. TikTok login failed. This may be due to application-specific settings. If youโ€™re a developer, fix the following and try again: code_challenge.โ€ Iโ€™m not doing any manual PKCE handling in my code, and I assumed BetterAuth manages it internally....

Cookie โ€œ__Secure-session_tokenโ€ has been rejected for invalid prefix.

i really dont know why, but i can't set cookie for client and cant login in my app

React JS - should auto redirect to login page when session expired

Hi Guys ! using better-auth with react js , i am using sessions for the auth things , my question is when the session get expired (in cookie) i want my react app to redirect to login page, does better-auth give any support for this ? i know i can use "https://www.better-auth.com/docs/basic-usage#signout" , but what i am asking instead of i am signing out react should auto sign out and move to login page when the session expired ! does better-auth support this ? if so how ? PS: using express for the backend...

Setting user role on sign up

Is it possible to set a users role when they sign up or just when an admin creates them?
Solution:
You can not set role on signup but you can use admin for that

How to delete a user creates with oauth?

Is there a way to use the deleteUser api for a user that, for example, signed up via google? As soone as the session isn't fresh the api required a password, but oauth users don't have a password. Do I have to manually cover these use cases? If yes, how can I generate my own token and send it to that user's email?

Github signIn returns `unable_to_get_user_info`

Hi people, I have a simple login with Github, but when it returns from Github, I'm getting unable_to_get_user_info error and I absolutely can't find anything related to this error. I'm using Nuxt integration....
Solution:
check your oauth keys?

useSession hook not callable

I just added better auth to my project and can't use the hook, I get an error saying:
No constituent of type 'Atom<{ data: { user: { id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }; session: { id: string; createdAt: Date; ... 5 more ...; userAgent?: string | ... 1 more ... | undefined; }; } | null; error: BetterFetchError | null; isPendi...' is callable.ts(2349)
No constituent of type 'Atom<{ data: { user: { id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined; }; session: { id: string; createdAt: Date; ... 5 more ...; userAgent?: string | ... 1 more ... | undefined; }; } | null; error: BetterFetchError | null; isPendi...' is callable.ts(2349)
Did I miss something in my configuration?...
Solution:
are you importing authClient from better-auth/react?

role-based authorization

Hi, I'm implementing role-based access control in my admin panel and facing a challenge. I need to restrict access so only users with user.metadata.role === "ADMIN" can log in. What's the recommended approach in Better Auth to: - Validate a user's role/permissions BEFORE creating a session? - Is there any equivalent to Next Auth's authorize callback that lets me check custom conditions during login?...
Solution:
thanks @Soheel i tried with hooks (not databasehooks), it worked ๐ŸŽ‰ I added this to my auth config ```ts hooks: {...