Better Auth

BA

Better Auth

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

Join

bug-reports

help

admin plugin ban user - unauthorized

How do I ban a user in a server side route? Thought thats the way how you perform actions on the server side ``` await auth.api.banUser({...
Solution:
provide headers, UNAUTHORIZED status is when you dont provide any authorization in your request

Post sign up hook for google provider

Hi, I've implemented a post sign up hook for an email provider where I send an internal event to my team when a user signs up. Now I would like to do the same for the google provider. Can you advice how I can identify when the user signs up (creates a new account) as opposed to logs in? Here's my existing after hook ``` hooks: {...

fs.existsSync is unavailable

i get this ero in my expo + API routes app when i deployed on eas Hosting (i'll still try to host on vercel to see if problem persists). ```TypeError: EAS Hosting: fs.existsSync is unavailable (Workers have no filesystem) at Object.fn [as existsSync] (__node_compat.js:904:11) at _expo/functions/api/auth/[...auth]+api.js:298:17611 at g (_expo/functions/api/auth/[...auth]+api.js:2:1781)...

Hashing script to seed database

The palace project - the cases forI am trying to create a python script that lets me seed my database with dummy test data. I need to create some accounts but I want to be able to actually log into these accounts which means setting passwords. However, I'm struggling to work out how to set the password in the db. I have tried a few different python scripts (my seeding is produced with python) but not succeeding so far. I have tried to mimic the same method used by better-auth. ```import os...

Using better-auth without a database

Hey, just a quick question, Can I use better-auth to do this: - oauth providers...

Type error in "signUp" after renaming "name" in "user" table

Hello, I'm trying to rename a column in the user table. Here is my auth config: ` user: {...
Solution:
You still need to use name in the signUp

Better Auth + Multi-Tenant (Separate DBs per tenant)

Hey everyone, Seeking advice on integrating Better Auth in a multi-tenant app where each tenant has its own Postgres DB. My current idea involves using Better Auth's hooks.before to dynamically create a prismaAdapter with the tenant-specific PrismaClient by modifying ctx.context.adapter. Is this a sound approach, or are there better/recommended ways to pass a dynamic Prisma instance to Better Auth per request? Also, any potential pitfalls or edge cases I should be aware of with this method? Open to all suggestions!...

JWT Err : Key for the EdDSA algorithm must be one of type CryptoKey

{"keys":[{"crv":"Ed25519","x":"E1Wd_QpdDtT914FDNKJNuPiXvdeUDMRaTtVN0vPRG6U","kty":"OKP","kid":"YIliaKY8X4nDAfHXWJzOpJrzYqgBQ11Z"}]}
{"keys":[{"crv":"Ed25519","x":"E1Wd_QpdDtT914FDNKJNuPiXvdeUDMRaTtVN0vPRG6U","kty":"OKP","kid":"YIliaKY8X4nDAfHXWJzOpJrzYqgBQ11Z"}]}
I've keep getting the bellow error in better auth,
I've keep getting the bellow error in better auth,
jwt({ jwt: {...

When signed in with Social providers authClient.useSession doesn't make requests to the server

I use better-auth/vue in Nuxt, everything is set up as in the docs, triple checked. With the same code everything works when I signed in with email/password credentials, I can see in the browser console that the session is fetched when needed. But with social providers it's not calling the server at all (I tested it with Google and Microsoft)....

API calls for auth not working in docker container

I am using SvelteKit and I do have the hooks.server.ts file, and it works just fine using pnpm run dev and even when I build it and run pnpm run preview. When I build a docker image however, the app loads just fine and everything works except for the /api/auth calls. I try with curl even and I just get the 404 page response. I have the base url set to localhost:3000, I am exposing the 3000:3000 port so everything matches and still nothing. Any ideas why?

Social Login doesn't work

Hey, I tried to use the signIn.social method with Google (also tried it with Discord but its the same problem). When I try to login it triggers the onSuccess function after some time and also gives the positive response: POST /api/auth/sign-in/social 200 in 237ms. But i don`t get forwarded to google nor logged in or anything. I am using Next.js 15. Thank you a lot for ur help!

How To Do Google Popup Login?

When my users click 'Sign In With Google", I don't want to perform a full page redirect. I want all the auth to happen in a popup so I don't lose the tracking session. How can I do that with better auth and next.js?

api/auth/get-session returns null in prod but works locally

hi, my backend is made with express/node.js and my frontend with nextjs but the get-session api returns null in production whereas everything works perfectly locally.

How to have databaseHooks event whenever user logs in?

This is my auth code. My goal is to save the date when user logged in. ```import { betterAuth } from "better-auth"; import { MongoClient } from "mongodb"; import { mongodbAdapter } from "better-auth/adapters/mongodb";...
Solution:
solved it myself, turns out that I had to use session instead of user

List sessions server side

Hello, I'm making a sveltekit app where after the login input, if credentials are right, the server look for other sessions of the user, if there is another session open (for example in another device's browser) there is a modal that asks for session removal (it's a web app and I need to limit multiple sessions) then the log in proceeds. Is there a way to use authClient.listSessions() on the server? Because I could login the user before and then prompt the session and log out if the other is not removed, but it looks more prone to exploits and I'd prefer server-side operations....

Database Hooks `before.create` Has Undefined Context

How is the context populated in the database before create hook? Taken from example here https://www.better-auth.com/docs/concepts/database#1-before-hook Code snippet below:...

❓ Help with better-auth: cookieCache not persisting after maxAge expires

Hey everyone, I'm using better-auth and I have cookieCache enabled (true) with maxAge set to 60 * 1 (1 minute). When I first log in, two cookies are set: better-auth.session_token better-auth.session_data...

Create user with custom ID

I am trying to configure better-auth as an alternative to Cognito. We are trying to migrate our users over, but since Cognito doesn't allow us to access the passwords, we need to do it when our user's log in. The idea is to log in with Cognito and sign the user into the better auth database. This means that the IDs should match. Is it possible to create a user with a pre-set ID, so that the old Cognito and the new user IDs match?...

Nextjs Dynamic server usage

By using headers in a function to get the userid on the server side, my page isn’t rendered statically anymore. Is there an actual clean server side logic to get the user Id?...

Social Auth throwing 500 error's

When i user tries to login using OTP it works fine and returns success however if a user tries to login using social auth (google or microsoft) it fails (throwing a 500 status code) there is not logs relating to auth errors though and everything looks correct. Social auth logins did work at some point and has started to fail. I am using the auth client on my api using Hono and cloudflare workers and my frontend is using nextjs please see the attached files or these links here: ...
Solution:
Turns out my db wasn't running for some reason and it wasn't erroring out which is super weird oh well fixed now.