mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* chore(deps): add next and react to dev dependencies * chore: move build configs to avoid crash with next dev * chore: add next js dev app * chore: remove .txt extension from LICENSE file * chore: update CONTRIBUTING.md * chore: watch css under development * style(lint): run linter on index.css * chore: fix some imports for dev server * refactor: simplify client code * chore: mention VSCode extension for linting * docs: reword CONTRIBUTING.md * chore: ignore linting pages and components
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import { useSession, getSession } from 'next-auth/client'
|
|
import Layout from '../components/layout'
|
|
|
|
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()`.
|
|
const [ session, loading ] = useSession()
|
|
|
|
return (
|
|
<Layout>
|
|
<h1>Server Side Rendering</h1>
|
|
<p>
|
|
This page uses the universal <strong>getSession()</strong> method in <strong>getServerSideProps()</strong>.
|
|
</p>
|
|
<p>
|
|
Using <strong>getSession()</strong> in <strong>getServerSideProps()</strong> is the recommended approach if you need to
|
|
support Server Side Rendering with authentication.
|
|
</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 getSession(context)
|
|
}
|
|
}
|
|
}
|