Next.js Discord

Discord Forum

Better-Auth (NextJS, Express)

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Hello,

We use NextJS 15 on the frontend and have a separate Express backend.
Now we want to implement Better-Auth (Switching from next-auth)

Central Auth Service: Express API
Frontend: 2x NextJS 15 and Expo Mobile App

If I only define the client in NextJS:
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
baseURL: "http://localhost:1337",
});

Then I can use useSession but can't retrieve the session server-side cause headers is not known.
import { authClient } from "@/lib/auth-client";
import { headers } from "next/headers";

const DashboardPage = async () => {
  const session = await authClient.getSession({
    headers: await headers(),
  });


I've done some research but haven't found any results after some testing...

How can I manage the ability to retrieve the session in NextJS both server-side and client-side with the Express Better-Auth backend?

0 Replies