When calling auth.api.getSession, why is the user key inside the session object sometimes undefined?

Server-side rendering a page on Next.js:
import { auth } from "./auth";
import { headers } from "next/headers";

export default async function Page() {
const session = await auth.api.getSession({ headers: await headers() });

if (!session) {
redirect("/auth/sign-in");
}

console.log(session) // user is sometimes undefined inside session, why?

// ...rest of component
}
import { auth } from "./auth";
import { headers } from "next/headers";

export default async function Page() {
const session = await auth.api.getSession({ headers: await headers() });

if (!session) {
redirect("/auth/sign-in");
}

console.log(session) // user is sometimes undefined inside session, why?

// ...rest of component
}
Generally, I am unable to access user when a user first signs up and then is redirected to an authenticated page. After some arbitrary amount of time, I am able to. I don't know why.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?