Next.js Discord

Discord Forum

Dynamic server usage: Route / couldn't be rendered statically because it used `headers`.

Answered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
Hey guys, So I have this weird problem, where I'm getting an error that just showed up today, and the app locally in development was fine all the time. Has anyone had that problem with AuthJS? I would prefer to stay with Authjs instead of Lucia. Below my code.
"use server";

import { auth } from "@/auth";
import { cache } from "react";

export const getSession = cache(async () => {
const session = await auth();
const user = session?.user;
if (user) {
console.log("user loaded");
}
// console.log("--------", session);

return session;
});

`

12 Replies

Chinese AlligatorOP
on the client side
I can't even use auth() on the client side
make sure you are not forcing the route to be rendered static
and also your function is a rsc
u cant run it on the client
for clientside session u can use this
Answer
Chinese AlligatorOP
it worked!
thx
@Chinese Alligator it worked!
u can mark my post as solution :)
@gin u can mark my post as solution :)
Chinese AlligatorOP
done 🙂