Why double auth call on server pages?

Why do server pages call auth() after calling a router but before page render if the router context already checks for auth?
export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" }); // this calls auth internally also
const session = await auth();

if (session?.user) {
void api.post.getLatest.prefetch();
}

return (
<HydrateClient>
//page
</HydrateClient>
);
}
export default async function Home() {
const hello = await api.post.hello({ text: "from tRPC" }); // this calls auth internally also
const session = await auth();

if (session?.user) {
void api.post.getLatest.prefetch();
}

return (
<HydrateClient>
//page
</HydrateClient>
);
}
1 Reply
lukas
lukas4mo ago
cmiiw: are you running in debug? if yes try to do it in prod, this may have changed, but i remember that by default nextjs ran react in strict mode when in dev, one of the things this does: renders components twice to make sure they are consistent might be wrong about this, havent been in react srsly for a while and idk how strict mode affects server components some docs you might want to take a look at: https://react.dev/reference/react/StrictMode i would recommend just checking if this happens when you run in prod, if not, then its prob this
<StrictMode> – React
The library for web and native user interfaces

Did you find this page helpful?