Better Auth

BA

Better Auth

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

Join

bug-reports

help

SignOut function doesn't immediately re-invoke session change

Hi, everyone I am currently implement auth in my project I followed the quick start from docs and it went smoothly But when I implement sign out and click it, it doesn't immediately show logged out display instead I have to reload the page to see the change? ...
Solution:
```ts export default async function MainLayout({ children, }: Readonly<{...

Get access to genericOAuth profile in customSession

Hi everyone, I have some user groups in keycloak and want to pass them to session.user. The groups are in the genericOAuth profile, as passed to mapProfileToUser. How can I access profile.groups from customSession? Thanks!...

Not able to get session type while using auth.api.getSession({headers: headers()})

I have an turborepo setup with below packages, i am trying to migrate from "next-auth" to "better-auth". I have all auth related code in seperate internal package "packages/auth". I facing very strange issue on which i am stuck from last 2 days. My problem is related to getting types for session, I am using auth.api.getSession to get session on serverside. I have tried everything, even when i am using this in auth.ts file itself it is not giving types. I have tried to use differnt tsconfig....

Help setting up better auth in a fetch environment

Hey! I am getting a 404 error when trying to call the better auth handler in my api handler. Does anyone know how I can solve this?
No description

Database Hooks within a Plugin

Hi, I'm working on a custom plugin which requires intercepting and editing the user data when a user is created. This would be easier with a database hook, but I cannot find a way to do a database hook in a plugin. Is there a way of doing this? Thanks....
Solution:
you can pass init ```ts const plugin = { init: (ctx)=>{ return {...

Where to get these ID token? the documents looks half.

Sign In with Google With ID Token To sign in with Google using the ID Token, you can use the signIn.social function to pass the ID Token. This is useful when you have the ID Token from Google on the client-side and want to use it to sign in on the server. ...

Auto logout

Hi, Im using nextjs + mongodb and Redis for caching. But when I update the site, some users getting logged out. and some was saying that it takes a few minutes to login again....

Infer additional fields for admin?

Is admin not able to infer types for additional fields like so when the types come from a plugin? I have added the InferTypes on the client plugin. ``` await admin.createUser({ name, email,...

Expo - In-app browser not showing up

Hi, I'm using better-auth hosted on a next.js backend With Expo, I'm following the documentation and the login button (physical and simulator) is not doing anything (no redirect, browser, etc.) ```ts...

Express error

Hello, i have an error with express as my backend. When i press the login button, this error happens. I tried changing cors like 3 times but no luck. anyone got a clue?...
No description

Cannot read user data after social sign in with google

After a successful login using google I need to use the user id, the type of the response says that I can read that information but it isn't accessible and I don't know what to do. Does anyone know how to get it or solve it ?...
No description

Google Oauth Scopes Error

src/lib/auth.ts ```ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { prisma } from "./prisma";...
Solution:
you should pass scopes as an array of string instead
No description

Conflict between Admin and Anonymous plugins – 500 error

Hello, I'm having an issue with two plugins: Admin and Anonymous. When I try to use Anonymous while the Admin plugin is enabled, I get a 500 error. However, if I disable the Admin plugin, Anonymous works perfectly. ...
No description

Question regarding callbacks (used by next auth)

On Next Auth lib there's the callback system that is called after a user is logged in. Is there something similar in better auth? I would like to do some work when user logs in/signs up.

I'm trying to disable some routes

I'm trying to disable some routes, I saw that there is a string array "disabledPaths". Mine is like this ```disabledPaths: [ '/change-email', '/list-sessions', '/list-accounts', '/unlink-account',...

Help handling JWT with Sveltekit

I am new to JWT but need them for a third-party API - what is the best practice to handle/cache them?

Custom Session running twice on GET /api/auth/get-session

I'm trying out custom session to return some additonal team fields on the repsonse to use on the client side and i noticed(sinces its making a call to the db and i have the logger on) it's running the custom Session method twice for every single call to GET /api/auth/get-session is this to be expected or have i done something funky in my config my custom session looks like the following: ```typescript customSession(async ({ user, session }) => { if (config.dev) console.log('custom session is running');...
Solution:
OK i had to do something funky i literaly had to copy over your customSessionClientPlugin and make this change ```typescript async (ctx) => { const session = await getSessionFromCtx(ctx);...

manual session refresh

Is there a way to refresh the existing session when we will the session freshAge?

Google redirect_uri_mismatch auth

my backend running on localhost:8000 front end running on localhost: 3000 here's my google redirect uri ...
No description

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...