Better Auth

BA

Better Auth

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

Join

bug-reports

help

accessing plugins in DB hooks

Just a question if it's possible or not to access plugins in the DB hooks. good example is creating an organisation when a user signs up? looked around the docs and couldn't find much...
Solution:

Caching a user session with multiple relations (drizzle-orm postgresql)

Hello, I was wondering what would be the best way to handle this problem. I have a user schema and relations made in drizzle like this: ``` export const user = createTable("user", { createdAt: timestamp("created_at", { withTimezone: true })...

Setting up a passwordless flow

I'm struggling setting up a passwordless approach. The use case is a website where people can buy a product using a Polar checkout, and on success Polar sends people back to /sucecss with their checkout id. Using the checkout id and Polar's sdk I get their email. At that point I create a user on better-auth with their email, but I don't have any password. From there, I'd like to just log the user in, so they can immediately see their dashboard and any premium thing they bought, but I can't manage to find the way to log people without a password or social sign in. Workarounds that don't work: crating a user before allowing them to purchase. This would add unnecessary friction when the main goal is to have them purchase, not to create a user....

Trying to use API key to access protected endpoints, still redirected to signin

I'd like to be able to make HTTP requests to endpoints protected by better-auth from a script using an API key, but I'm having trouble. I can successfully generate an API key, but whenever I use it under the "x-api-key" header in subsequent requests, I get redirected to the signin page. Per the API Keys docs: "Any time an endpoint in Better Auth is called that has a valid API key in the headers, we will automatically create a mock session to represent the user." https://www.better-auth.com/docs/plugins/api-key#sessions-from-api-keys However, based on the redirection to /signin, I'm guessing it's not automatically creating a mock session? Or maybe my API key is not valid?...

Account blocked after failed login attempts

I would like to be able to block user account if login attempt fails multiple times. Im not sure how to achieve this with better auth. Unsure if I can somehow override current auth route to point towards a new one where this logic will be managed, but still does the user login such that frontend still uses the ```tsx const { data, error } = await authClient.signIn.email({...

admin createUser doesnt work

Hey folks, im trying to make user and i get this error,
POST /api/auth/admin/create-user 401 in 6457ms
{ data: null, error: { status: 401, statusText: 'UNAUTHORIZED' } }
POST /api/auth/admin/create-user 401 in 6457ms
{ data: null, error: { status: 401, statusText: 'UNAUTHORIZED' } }
...

ApiError missing .code in type for haveibeenpwned?

So I installed the HaveIBeenPwned plugin which works, but when handling the error which sets code to
PASSWORD_COMPROMISED
PASSWORD_COMPROMISED
it seems that ApiError type doesn't have the code property so i get a typescript error (but my code works). Am I missing something here or is this just a bug? ``` catch (e) { error.value = e as APIError; if (error.value.code === "PASSWORD_COMPROMISED") {...

OIDC JWKS Support Guidance

Sry to keep bothering on this: On OIDC JWKS support you have oidc missing native jwks support and the jwt plugin. On a couple of unmerged PR's effectively you have "useJWTPlugin" and their splicing the functionality in. Is that the eventual goal or are you planning on doing something else? Is that the likely solve for OIDC or are you planning on writing separate functionality? ...

How to identify a user ID when a server receives requests?

Are this steps correct? or there is the method? 1. Receive requests 2. Get a session token in the cookie...
Solution:
I solved that!! app/api/record/route.ts ``` import { headers } from "next/headers";...

[Session Refresh] Is it possible to only refresh session if it was created within a time range?

In my project, sessions should expire after 30 minutes of inactivity or after 8 hours, regardless the activity. The first half could be achieved by configuring the expiresIn option, but I don't know if the latter is doable. Thank in advance!!!...

migrating from supabase

hey folks, im moving RLS policies i had from supabase to pgSQL railway, and in supabase there is auth.uid() which fetches uid from user, what is a substitute for that so it works for pgSQL?

Auth config for the client side visualization

Is there any way to get auth config via any endpoint, which can be used in the front-end for visualization, means if emailAndPassword is enabled, what are the social login available, what are the plugins available, based on these details, we can customize the signin UI.

'useRef' is not exported from 'react'

Hi, on my NEXTJS website I try to install better auth and I have this error that I can't solve
No description

would it break anything if i manually create users?

I am wondering if it would break better-auth in any way should I manually create users via drizzle -- for example, if I want to add "guests" that can't sign in or do anything else, but have a record in the users table so that other table schemas can have a nice foreign key ref.

Hashing E-Mails

Does anyone have experience with writing and reading emails as hash from the dabase using oAuth and Magic-Link as authentication options? I tried some approaches using databaseHooks for storing the email as hash and Better Auths hooks for finding the hased email in the database but i just cant seem to get it to work.

New to better-auth

Hey folks, since better-auth generates own tables, can i modify that? I want it to be linked to my own users table, would that do anything bad?

how to list user organizations on server side?

i only found the authClient.useListOrganizations() but how would i go about getting that on server side?

Auth failure

Hi guys i have two separate apps a nextjs and a honojs backend both using better-auth for some reason i cant make a login request it just returns the following error ...

Email Verification Callback after Email Change

When you change the email of a verified user, and provide a callback url, an email is sent to their current email to confirm the change with that callback, but then another email is sent to the new email to mark their new email as verified, but what will the callback url for that email be? How can we customise it?