You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{getServerSession}from"next-auth/next"import{authOptions}from"./api/auth/[...nextauth]"import{useSession}from"next-auth/react"exportdefaultfunctionPage(){const{data: session}=useSession()if(typeofwindow==="undefined")returnnullif(session){return(<div><h2>Protected Page</h2><p>You ({session.user.email})can view this page because you are signed in.</p></div>)}return(<div>Access Denied</div>)}exportasyncfunctiongetServerSideProps(context){return{props: {session: awaitgetServerSession(context.req,context.res,authOptions),},}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have followed the next-auth tutorial at
https://next-auth.js.org/getting-started/example
and although is written for Next.js, with minor changes, everything works smoothly for Nextra. You can find my notes about those minor changes at
https://ull-mii-sytws.github.io/next-auth-getting-started/#reading-getting-started-with-nextauth-js
But when I arrive to this example about securing a page on the server side:
https://next-auth.js.org/tutorials/securing-pages-and-api-routes#server-side
The example of the tutorial does not work with nextra. Here is the Error I've got:
And here is the code:
➜ nextra-casiano-rodriguez-leon-alu0100291865 git:(guide) cat pages/serverSideProtectedExample.jsx
Can someone help?
Beta Was this translation helpful? Give feedback.
All reactions