Files
archived-next-auth/apps/dev/pages/server.js
Olaf Görlitz 18e8b92289 fix(dev): fix import links for authOptions (#8938)
* fixed instruction link

* fixed import link of authOptions in dev app

* deleted old, obsolete authOptions

---------

Co-authored-by: Thang Vu <hi@thvu.dev>
2023-11-04 16:02:53 +07:00

47 lines
1.5 KiB
JavaScript

import { getServerSession } from "next-auth/next"
import Layout from "../components/layout"
import { authOptions } from "/app/api/auth/[...nextauth]/route"
export default function Page() {
// As this page uses Server Side Rendering, the `session` will be already
// populated on render without needing to go through a loading stage.
// This is possible because of the shared context configured in `_app.js` that
// is used by `useSession()`.
return (
<Layout>
<h1>Server Side Rendering</h1>
<p>
This page uses the <strong>getServerSession()</strong> method in{" "}
<strong>getServerSideProps()</strong>.
</p>
<p>
Using <strong>getServerSession()</strong> in{" "}
<strong>getServerSideProps()</strong> is currently the recommended
approach, although the API may still change, if you need to support
Server Side Rendering with authentication.
</p>
<p>
Using <strong>getSession()</strong> is still recommended on the client.
</p>
<p>
The advantage of Server Side Rendering is this page does not require
client side JavaScript.
</p>
<p>
The disadvantage of Server Side Rendering is that this page is slower to
render.
</p>
</Layout>
)
}
// Export the `session` prop to use sessions with Server Side Rendering
export async function getServerSideProps(context) {
return {
props: {
session: await getServerSession(context.req, context.res, authOptions),
},
}
}