session null in nextjs route handler

I know auth and sessions is working because it I can log in and out with no problem. My server functions are able to get sessions but whenever I try and get the session from a route handler it's null This same function is used throughout my app and works everywhere except route handlers
const session = await auth.api.getSession({
headers: await headers(),
});

if (!session) {
return {
user: null,
session: null,
};
}

return {
session: session.session,
user: session.user,
};
const session = await auth.api.getSession({
headers: await headers(),
});

if (!session) {
return {
user: null,
session: null,
};
}

return {
session: session.session,
user: session.user,
};
1 Reply
Shaki
ShakiOP3w ago
I found the fix. You have to pass the headers to the api call inside of your server component

Did you find this page helpful?