Best way to get session data server-side when using separate backend?
Hey there
I'm using Next.js in a monorepo setup, so my
Anyone recommend a better solution?
PS: I think it would be convenient to reuse
betterAuth instance is not in my Next.js project. I could import this instance since I am using a monorepo setup, but I do not want duplicate instances. Typically on the server, we merely call auth.api.getSession({ headers: headers() }) . Client-side, we call authClient.getSession() and we're good. But what if we want to call getSession server-side when we don't have the betterAuth instance? I have tried using the authClient instance, but it only returns null. An LLM conveniently solved this problem for me, but I suspect this is the incorrect solution and perhaps the authClient is supposed to be used here.Anyone recommend a better solution?
PS: I think it would be convenient to reuse
authClient and just manually specify the headers as we usually do server-side.Solution
Found the solution. Seems obvious in retrospect! Simply pass headers manually using
fetchOptions.