Better Auth

BA

Better Auth

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

Join

bug-reports

help

newbie: are my conventions for checking if a user is logged in on client and server side fine?

hi so this is my first time rolling my own auth. ive used clerk before. the db im using with better auth is mongodb as my user data is there rn. We only need google auth (no email/password). I've gone through the installation and setup and ive got google user logins registering in my mongodb collection. The question I have is, am I properly checking if the users logged in (client and server side)?...
Solution:
For guarding routes, use middleware to redirect users - but don’t fetch the session in the middleware, just rely on cookies (there’s an example in our Next.js integration docs). For protecting pages, fetch the session in an RSC component and decide what to render based on that. Regarding performance, make sure to use cookies in the middleware (without fetching the session), enable cookie cache, and make sure to proper DB indexes (explore optimization methods from the docs) https://www.better-auth.com/docs/guides/optimizing-for-performance...

Stripe Embedded Checkout

Are embedded checkout pages supported by the stripe plugin?

auth.api.getSession not refreshing session_data cookie

Hi, I am using better-auth with sveltekit. My auth.ts has session.cookieCache to true and maxAge of 1 second for testing purposes. ...
Solution:
the issue is when you use api.getSession it can't set the cookie in your browser unless you do it manually

Better auth organization

Please how implement organization pluging of better auth to system de school management where all model on db point to school table in this case organization. And can add some attributs manually on models ? I'm not english natif so.

Seeding an admin user

I want to seed an admin user in my Express app. export const auth = betterAuth({ appName: 'LaundryApp', basePath: '/api/auth',...

How to get type for permissions

I'm using the organisation plugin and i have created some custom roles. On the client I have a sidebar where some items are gated depending on the role of the member. So i don't have to go back to the server multiple times, im calling getActiveMember in my layout and passing the role of the active member into the sidebar and then making use of authClient.organization.checkRolePermission. I'd like to specify in a central location all my sidebar items and groups and what permissions are needed to access the page. ...

how to map custom schema with better-auth

my drizzle tables eg: ``` export const Users = pgTable( "users",...

Admin List Users not returning Pagination data

Hi guys! I just recently updated my better auth to 1.2.4 because previously on 1.1.1 I was only able to get the list of users from the listUsers API. However, after upgrading I'm still not able to get the pagination information from this endpoint. Any idea why? ```const response = await authClient.admin.listUsers({ query: {...

inferAdditionalFields doesnt work?

Im trying to use authClient.signUp.email function on client side. But i cant see my Additional fields on client side. I can see them on server side. ```ts auth-client.ts ...

newbie: are my conventions for checking if a user is logged in on client and server side fine?

hi so this is my first time rolling my own auth. ive used clerk before. the db im using with better auth is mongodb as my user data is there rn. We only need google auth (no email/password). I've gone through the installation and setup and ive got google user logins registering in my mongodb collection. The question I have is, am I properly checking if the users logged in (client and server side)?...

Organization Member List get if two factor Auth is enabled

Hii, when I call authClient.useActiveOrganization() in SvelteKit, I'll get the Organization Data including a array with all members. I'd like to include the data if the member has two factor enabled, if his email is verified and if hes banned. Is there any way to do this besides making my own call to the database? Thank you! :)

Updating Discord Image

Hello, Is there a way with the Discord auth to update the image of the user everytime they sign in, or do we need to manually check if the image is still valid, and then update it if needed ?

Custom Fields

Hey! How can I do custom additional fields like Containers? Users can have containers which have a name and image.

JWKS Error

Hello, I set up the oidc provider and configured the sso plugin, but when I tried to log in with sso, this is exactly where I got stuck const key = keys.find((key) => key.kid === header.kid); ...
No description

Prisma + Better Auth + Turborepo Issue 🤔

Hey everyone! Here's what's happening: The Setup - Using a Turborepo with Next.js - Prisma schema is in a separate package (packages/database)...

Providing additional fields when signing up via magic link

Hey there, when I sign up via magic link from the client with the code below I'm not able to pass custom / additional user fields (i.e. firstName, lastName). Or do I miss anything? const { error } = await authClient.signIn.magicLink({ email: data.email, callbackURL: returnUrl,...

creating the first user, where disableSignUp is true

Hi, are there any suggestions on how to do this? I've created the DB schema fine but with this off and no API in place yet I was hoping there'd be a CLI command

Can not change the issuer and audience of JWT header and also the payload

So tried to change the issuer and the audience of my jwt config by following the documentation but it's not working as expected here it's my config ` 'plugins: [ jwt({ jwt: { issuer: env.BETTER_AUTH_URL, audience: env.REDIRECT_PROXY_URL,...

How to implement invite-only registration flow with better-auth?

Hello, I'm looking for some help on how to implement this use-case. Here is the general user creation/registration flow I want to implement:
1. Existing admin user adds a new user by entering their email (and possibly name and role). 2. The new user receives email with a welcome message and a link (time limited) to complete account setup. 3. After clicking the link, the user is redirected to a page where they can enter a password and/or link their social account....
Solution:
we'll have sendInvite functionality in the admin plugin soon but magic link or forgot password for the time being should work fine

How can I make better-auth typesafe?

I currently trying to make a list with all members and invitations, but I constanly running in typing errors.
No description