Performance: Server-side session access
MEDIUM IMPACT
This affects the time to first byte (TTFB) and overall server response time, impacting how quickly the page starts rendering.
import { unstable_getServerSession } from 'next-auth/next'; export async function getServerSideProps(context) { const session = await unstable_getServerSession(context.req, context.res, authOptions); return { props: { user: session?.user ?? null } }; }
export async function getServerSideProps(context) { const session = await getSession({ req: context.req }); // heavy synchronous session parsing or multiple session reads return { props: { user: session.user } }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous session parsing | N/A (server-side) | N/A | N/A | [X] Bad |
| Optimized async session retrieval with caching | N/A (server-side) | N/A | N/A | [OK] Good |