Better Auth

BA

Better Auth

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

Join

bug-reports

help

Custom Admin Role - Admin Plugin

I am trying to add an additional Admin Role to the Admin Plugin. I believe I have it set up according to the docs, but when I try to for example run authClient.admin.listUsers with my custom role, I receive the YOU_ARE_NOT_ALLOWED_TO_LIST_USERS Error. If I switch that user's role back to the default of 'admin' everything works as expected. I added screenshots of auth.ts, permissions.ts, and the function used to list users. Anyone have an idea on what I am doing wrong when creating a custom role?...
No description

Property 'surname' does not exist on type ...

I added custom surname field to user, added it inside additional fields in config but when using {session.user.surname} i get the error above even though surname clearly exists and is correctly displayed on the page

Server side Stripe usage

Hi, I'm focusing to use better-auth mostly (only) on the server, my client code is not aware of better-auth. My stack is deno + hono + htmx. So for it goes well. Hono route gets form data, calls auth.apisignInEmail and handles the response from that. Works good, I like that approach. Now I need to setup payments. Docs says I need auth client. IS there a way to deal with that only o nserver side? Of course I understand I will need some Stripe clienta at some point to show checkout ui, but I wonder how far I can get with my server-only apporach?...

Kinde to Better-Auth

Hello, since the development of this library has impressed me a lot, I want to switch to it, but there is such a problem. In the integration I established with kinde auth before, user ids were kept as autoincrement int in my own database, how can I transfer the data here now?

Custom Auth to Better Auth

I want to convert my custom auth apis into better auth. The problem is that I couldn't understand how to have more than two roles user and admin in better auth. It is an ecommerce web with user/vendor/admin roles, with varying profile information based on those roles.

Server email OTP authentication

It appears, from reading the docs, that email-and-password can be done if you're doing server-side auth only, however email-OTP is not currently supported. Am I missing something? I've got it working by having the server use the client library, but that's kind of ugly. Thanks!

ctx.redirect not working?

When the user is signing in, I want to check for something in the additional fields and redirect based on that. But even this simple redirect script doesn't seem to work. ```typescript export const auth = betterAuth({ // other config...

Question about Access Control and Orgs

Hey. I'm relatively new to the world with Teams and Orgs. In my previous projects there were only like site Admins, Moderators, users and maybe guests. Now I would like to try the new Permission stuff in the Org plugin but I don't really know how to set it up the best way. My first thought would be creating one Org that holds all users of the page. Then deactivating org creation etc.. and set max members to a very high number. If later social features would require it I can introduce additonal orgs. Or how should I set it up? Currently and in the near future there is no need of multiple orgs or teams. Thanks!...

Send session on each request

Should we send the session or access token as a bearer token on each request or does it already do that?

Phone number sign up doesn’t create a record in the Account table?

Hello I want to use better-auth for my nextjs app with phone numbers only authentication. sign up is fine but login complains that there’s no credential account found. This is my code for sign up right now that works correctly: await authClient.signUp.email({...

How to add query parameters to Polar checkout URLs?

Hey there, following https://docs.polar.sh/features/checkout/links#query-parameters you can add parameters like discount_code to the checkout url and have them prefilled in the UI. – That does not seem to work with the Better Auth plugin. Do I miss anything? I've tried: https://localhost:3000/api/auth/checkout/pro-annual?discount_code=X...

Custom Fields in Organization Table Not Saving Values

I'm having an issue with custom fields in the organization table. I've added company_size to my organization schema, but although the field exists in the database, the values I pass are never saved (always null). Here's my organization plugin config: ```typescript...

Change User table primary key name

Hi everyone, is it possible to change user table primary key? This is what i've dont but it doesnt seem to work for primary key field: ```js export const auth = betterAuth({ database: prismaAdapter(prisma, {...

How to Host better-auth on another Server

Hey, How can I host a my App (domain.com) separate from a better-auth Server on e.g. (auth.domain.com)? And Optionally how can I use that better auth Server for Allowing sign-in to multiple different Apps (for example like Google, Google Docs, YouTube) Thank you all...

Issue with error redirection in case of a custom domain setup

I am building a no-code tool to build custom apps. Each app can have multiple users (email/pass based login). Each app is hosted on its own subdomain app1.domain1.com, app2.domain2.com, and so on. When better-auth is used in a custom domain/multiple subdomain setup, the base URL is not known at build time but rather at runtime. When logging in via a social provider, let's say Google, if there is an error, the redirection is made to the baseURL defined in the context: throw c.redirect(${c.context.baseURL}/error?error=state_not_found); The ideal redirection should be to the client's subdomain. What is the best way to go about this?...

Trigger Session update ( to update user data)

Hey im updating user data after signin with google basically I assign a username and a checkbox to agree TOS. User is always redirected this onboarding page as long as he has 'pending' role. basically, after he submit his data i update him to a user role and he can browse the app now. How can I trigger/refresh session data to get the current state of the user from db? ...

additionalFields need defaultValue even for non required field

Hey i have the error that there isn't defaultValue on my field but my fiel has to be not required, and i try to connect using google oauth, on my express app. Can someone help me understand why it says it needs a defaultValue (and i try with or without the line defaultValue: "" but same issue) ? thank you all 😉...

Cross domain cookie / backend behind cf tunnel

Hi everyone, Does anyone have a setup where the back end is behind a cloudflare tunnel? I am dealing with a cross domain cookie issue and would love some help on resolving it. ...

The inferred type of 'authClient' cannot be named without a reference to [email protected]

Currently having an issue with undici:
The inferred type of 'authClient' cannot be named without a reference to '.pnpm/[email protected]/node_modules/undici-types'. This is likely not portable. A type annotation is necessary.
The inferred type of 'authClient' cannot be named without a reference to '.pnpm/[email protected]/node_modules/undici-types'. This is likely not portable. A type annotation is necessary.
My auth client:...

Init Drizzle with cloudflare env variables

I'm trying to connect my database with the drizzle adapter. My backend will be hosted on cloudflare workers (with hono) so I can't use process.env to get my environement variables. How to get my cloudflare env variables to the db init ? Thanks for your help! ...
Solution:
```ts import { drizzle } from "drizzle-orm/d1"; import * as schema from "./auth-schema"; export const createDrizzle = (db: D1Database) => drizzle(db, { schema });...