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 to set ExpireAt for user

Hello Better Auth community šŸ˜† Im trying to add a datetime to set an expire date for certain users. I was able to cancel a creation of new session in sign-in but having trouble canceling an update of a session. ...

Can we handle signing in with arbitrary credentials?

Like Next-Auth with credentials provider feature, my use case has to handle with sign in with specific auth flow that uses an authorization code (isn“t magic link). Basically the user sign flow is to be redirected to third-party system and came back with an authorization code that I verify if its valid. ``` providers: [...

[Urgent] Not getting custom session while using apikey

I have a custom session setup that works perfectly with traditional logins, but when I use an API key, I get the default key-values of the session object

Cookies not working localhost when API already in aws lambda (hono)

I'm trying to work with front-end in localhost but using the api in aws lamba. The cookies not working. When sign-in, the request returns 200 but getCookies return null and not redirecting to dashboard. Anyone already had this issue?!

Api key plugin with Prisma and express server

Hi everyone, Has anyone gotten the api key plugin working with prisma in a separate express.js server? i've implemented the ApiKey schema like so:...

Facing Issues in Session Management in Client side

I am using Better Auth for my new project. But I'm facing issue with session management and redirection. My goal is to redirect the user to the login page and log out automatically. I tried this function to get the session data, but it gives null value. const { data: sessionData } = await authClient.getSession(); I have tried to use this, but I cannot understand it fully....

generateName in Anonymous plugin for username instead of name

I saw the PR for maintaining unique names in anonymous but does that work for username login and how can I set the username? I seems like generateName only works with name not username

Customize login error response

Is there a simple way to customize the login error codes? I see that we get the specific response in the backend (invalid password, user doesn’t exist) - but it’s generalized when passed to the client (ā€œinvalid password or userā€ — or something like that). I understand the intent here from a security perspective, but in my use case, I’d rather pass the specific response to the user (and be able to interpret and customize the message depending on the error codes thrown). Is there a simple way to do this?...
Solution:
Ah. Before hook did the trick. Nm.

Going insane because I loose permissions when signing in with different account

Hey everyone, I just migrated my nextjs app from supabase auth to better-auth and I'm really happy with it. When trying to setup permissions with the admin plugin I encountered one issue which I just can not solve. (Starting with a blank db): I signup with a new account and make the account an admin account through the db dashboard. Eyerythin works fine now. I can fetch data, take actions etc. But when I create a new account in a different (incognito) window and sign in, everything breaks. I'm losing all permissions on both accounts (user role and admin role) and cant fetch data. Do you guys have any idea what the problem could be?...

Cant manually set cookie using authClient on the server

So first up to make sense of the title. i have a sveltekit app and a hono app. hono has my auth instance and sveltekit only has access to the authClient. Now i have a bit of a special login where i need the user to fill in something and on the server we add some parts to the username basically. Im not sure why my approach dosent work because: 1) the signIn function works fine and returns success with data...

Magic link not creating account

Some users signed in using magic link in their first time and when they try to sign in with magic link again, the link's not working. I've noticed that signing in with magic link doesn't create an account in accounts table. Could that be the issue? I've tried only signing in with magic link and it worked even though account is not created. Is magic link supposed to be used only for signing in, not signing up?

šŸ†˜ Field mapping issue with organization plugin: 'userId does not exist in schema for model member

Hello Better Auth community šŸ‘‹ I'm having an issue with the organization plugin and field mapping. When trying to create an organization, I get this error: ```...
No description

How to make username a requirement on oauth?

How can I make the username field a required value, alongside the session type? Also, is it possible to prompt the user to create a username after signing up with OAuth and prevent account creation if the username is not provided?

How to use const session = c.get("session") and const user = c.get("user") in Hono when routes?

Hi everyone, I'm using Hono but the only way I can retrieve c.get("user") is if I export my app variables type? Is there a more elegant way to do this? Maybe export the "whole app" in each route instead of just variables? index.ts:...

Betterauth GitHub login not reliably redirecting to github.

I have everything set up like the docs tell you to. I have a button with a onclick calling the github signin. This, for some reason, doesnt reliably redirect to github tho. Sometimes it works perfectly, sometimes all it does is reload the page with a ? at the end, nomatter how hard I try. Any Ideas on what this might be?...
Solution:
the button is submitting the form

How do I setup Discord OAuth2?

I have a Hono API running on localhost:3001 and a NextJS app on localhost:3000 On the server I have setup trustedOrigins and allowed localhost:3000 On the client I have set the baseURL to localhost:3001 And in the Discord Developer Portal the redirect URI is set to localhost:3001/api/auth/callback/discord...

How to add organization details to JWT claim?

Wondering how we can add these details via the jwt plugin?

404 Error for /api/auth/sign-up

When attempting to access the sign-up endpoint via /api/auth/sign-up/email, the SvelteKit app throws a 404 error: ```bash SvelteKitError: Not found: /api/auth/sign-up/email at resolve (/home/ubuntu/v2/frontend/node_modules/@sveltejs/kit/src/runtime/server/respond.js:582:13)...

The edge runtime does not support Node.js 'net' module.

I couldn't find work around for this fix. Here are my middleware.ts and auth.ts files....

"[object Object]" is not valid JSON

i am using nextjs 15.3.1 app router with typescript, betterauth 1.2.7. ```tsx import { auth } from "@/lib/auth"; import { headers } from "next/headers";...
Solution:
thanks @KiNFiSH . this fix worked for me - ```ts get: async (key) => { const value = await redis.get(key); return JSON.stringify(value) || null;...