Better auth does not work on NextJS

Hi guys, im trying to add Better Auth to my empty nextjs project but it does not work. I copied the demo project and it does work there, i copied every auth related file but i still cant get it to work in my project. im trying to check the session on a server component like this but the session is always null. I have not added a database as i dont need one, im logging in using my google account. I keep getting redirected to /sign-in and the console shows this error:

2025-04-20T19:46:49.619Z WARN [Better Auth]: No database configuration provided. Using memory adapter in development
[Error [APIError]: ] {
  status: 'UNAUTHORIZED',
  body: undefined,
  headers: {},
  statusCode: 401
}
 GET /dashboard 307 in 67ms
 GET /sign-in 200 in 65ms


My dashboard page:
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";

export default async function DashboardPage() {
  const [session, activeSessions] = await Promise.all([
    auth.api.getSession({
      headers: await headers(),
    }),
    auth.api.listSessions({
      headers: await headers(),
    }),
  ]).catch((e) => {
    console.log(e);
    throw redirect("/sign-in");
  });

  console.log(activeSessions, session);
  return (
    <div className="w-full">
      <div className="flex gap-4 flex-col">
        <h1 className="text-2xl font-bold">{session?.user}</h1>
      </div>
    </div>
  );
}
 
Was this page helpful?