MCPcopy
hub / github.com/nextauthjs/next-auth / Page

Function Page

apps/dev/pages/server.js:5–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import { authOptions } from "/app/api/auth/[...nextauth]/route"
4
5export default function Page() {
6 // As this page uses Server Side Rendering, the `session` will be already
7 // populated on render without needing to go through a loading stage.
8 // This is possible because of the shared context configured in `_app.js` that
9 // is used by `useSession()`.
10
11 return (
12 <Layout>
13 <h1>Server Side Rendering</h1>
14 <p>
15 This page uses the <strong>getServerSession()</strong> method in{" "}
16 <strong>getServerSideProps()</strong>.
17 </p>
18 <p>
19 Using <strong>getServerSession()</strong> in{" "}
20 <strong>getServerSideProps()</strong> is currently the recommended
21 approach, although the API may still change, if you need to support
22 Server Side Rendering with authentication.
23 </p>
24 <p>
25 Using <strong>getSession()</strong> is still recommended on the client.
26 </p>
27 <p>
28 The advantage of Server Side Rendering is this page does not require
29 client side JavaScript.
30 </p>
31 <p>
32 The disadvantage of Server Side Rendering is that this page is slower to
33 render.
34 </p>
35 </Layout>
36 )
37}
38
39// Export the `session` prop to use sessions with Server Side Rendering
40export async function getServerSideProps(context) {

Callers

nothing calls this directly

Calls 3

getServerSessionFunction · 0.90
getServerSidePropsFunction · 0.70
getSessionFunction · 0.50

Tested by

no test coverage detected