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 does callbackURL work with expo routing

Hey I'm new here and I'm trying to use the callbackURL in the authClient.signUp.email function. I tried to read several answers about this topic on this server and tried to read the docs but just got more confused. As far as I understood, it redirects the user to the page of the path assigned to callbackURL upon successful signup. I am talking about expo routing. So, for example /(protected)/(onboarding) or something like that. But maybe I got it totally wrong, would really appreciate some clarification....

Get Stripe subscription by User Id

I'm getting successfully subscription on server side using auth.api.listActiveSubscriptions, but i'd like to get user subscription by userId. The documentation doesn't specifies how can i do it. Exists any form to do that using the plugin or i need to implement the full subscription retrival by userId from scratch?
Solution:
Hello João! You could query the DB directly, this is an example using Drizzle but it's mostly the same (the referenceId can be either the user ID or the org ID): ``` export const getSubscription = async (referenceId: string) => { return db.query.subscriptions.findFirst({ where: eq(subscriptionsTable.referenceId, referenceId),...

get-session returning null with 200 status code

I'm running into an issue locally where occasionally the session will be returned as null for a signed in user. This leads to all getSession calls failing even with a valid session. I'm using Upstash redis as my secondary storage, and looking at the logs it doesn't appear that the session is even being access from the database (not seeing logs in either the "get" function in my better auth config or any requests through the Upstash console). This will happen periodically when developing locally, then resolve itself after a few minutes and page refreshes. Looking at the browser cookies, the session token doesn't change, the getSession calls just seem to start actually accessing the db again. Any advice on debugging this? This seems similar to github issue: https://github.com/better-auth/better-auth/issues/2055, but my requests are coming from a client component, and the getSession calls are failing in regular nextjs route handlers (as well as the get-session auth api call)....

The inferred type of this node exceeds the maximum length the compiler will serialize.

Getting the following error as soon as I add the organizations plugin. Thanks!
No description

ip Address is not stored in db

i am trying implement anonymous login plugin when user visits the website it automatically login him as guest and ip_address to track the usage instead of storing it in LocalStorage

Centralized Auth with Better Auth Across Multiple Domains – CORS Issues

Hey! I’m using the Better Auth framework in a Next.js dashboard app. I’m now splitting the app into three separate dashboards across different domains and want to use a single server for authentication. However, I’m running into CORS issues. The simplest workaround seems to be running auth separately in each project, but that feels redundant. Has anyone dealt with this and found a clean, centralized solution? Appreciate any insights!...

help on how to structure schema

lets say on a basic todo example, if we want an user specific todo, what id do I use to add it to the todo? do I need the user id or the account id, or the id in account table? or there is a better way to make private data to specific users? Im using drizzle, should I use a foreign key or something to reference on the table?...

Manual Setup? Cannot run @better-auth/cli generate

This may become a bigger problem down the line as well, I am not sure. I am attempting to go through the initial setup. My app runs on Cloudflare workers, which does not have access to process.env. Instead I must pass the variable to it from a context. ``` export const auth = (DATABASE_URL: string) => { return betterAuth({...

Phone number verification with twilio verification

I'm using phone number plugin with twilio service for phone number verification. Is there a way to use twilio phone number verification instead of using the code sent by better-auth? Thank you in advance!

Forgot password link doesnt handle query params in the redirectUri

For a url like this: https://auth.staging.company.com/auth/reset-password/rEjo8qGzUJNTQ1YbhVhaiuMA?callbackURL=http://localhost:6006/iframe.html?args=&globals=viewport%3Aiphone13pro&id=embed-pages-account--iframe&viewMode=story The url that I get redirected to is: http://localhost:6006/iframe.html?args=&token=rEjo8qGzUJNTQ1YbhVhaiuMA but it should instead keep the query params...

Help with organization & user management

Hey guys, I’m working on an app using Better Auth and need help figuring out how to support multi user access per organization (e.g. a restaurant). Here’s our current flow: A user signs up with email & password they’re effectively creating a "restaurant" account....

listAccounts()

I'm signed into an account in my app but listAccounts() is returning null unauthorized. Am I missing something that needs to be passed to listAccounts? ``` const accounts = await authClient.listAccounts(); // unauthorized console.log("accounts in authentication form", accounts);...
Solution:
Yeah, every authClient method is avalible in auth.api as well.
auth.api.listUserAccounts({headers: await headers()})
auth.api.listUserAccounts({headers: await headers()})
...

Migrating Supabase Auth only (dbs in neon)

Title, basically. Our database is in neon but we left auth in our original supabase. Any suggestions on how to migrate? We are pre-production, I'm assuming we can simply start over no?

tanstack integration question

I have a question regarding the tanstack start integration. It says we should use the the reactStartCookies() plugin from better-auth/react-start and that it needs the to be the last plugin in the setup. It also says, that it's recommended to use the client SDK or authClient. What is the client SDK? Is that better-auth/client? If so what is authClient that is mentioned in the same sentence? ...

NextJS handler not setting the cookie in production

Hey 👋 , My handler isn't setting the cookie on the client browser in production only. I'm using next 15.3 and better auth ^1.2.7 ...

Session management returns null even after successful signup and login

seem to be logging out null values for sessions when i call the api. Below is my implementation of protecting routes in sveltekit import { auth } from '$lib/auth'; import { redirect } from '@sveltejs/kit'; import { svelteKitHandler } from 'better-auth/svelte-kit';...

Help on implementing custom auth

Hey so guys I have email and passwd auth but I'm building a dapp so I wanna add a "continue with wallet feature" any ideas on how to go about this?

How to make authenticated fetch request using Tanstack query?

I am having trouble figuring this out. Apologies, if this is something very straightforward which I am missing. How can I make an authenticated request to an API? In Expo, I can do this, ```ts const makeAuthenticatedRequest = async () => {...

useSession Causing Hydration Mismatch Inside Suspense

You can see the video, using useSession inside Suspense will cause hydration mismatch error, but if i remove the Suspense, the error disappear. Current solution is to use isMounted before render anything from useSession...

Discord Invalid Scope

Hello. I was attempting to add an additional scope, activities.read, under the Discord section and I keep getting an error - Is there any workaround/fix to this? Thanks! P.S. The scope with identify and email is okay but whenever I add the one mentioned previously, it just throws an error....