Next.js Discord

Discord Forum

Get context in App Directory

Unanswered
Black-headed Gull posted this in #help-forum
Open in Discord
Avatar
Black-headed GullOP
import { NextPageContext } from "next"
import { getSession, signOut } from "next-auth/react"

export async function getServerSideProps(context:NextPageContext) {
const session = await getSession(context);

if(!session) {
return {
redirect: {
destination: '/auth',
permanent: false,
}
}
}

return{
props: {}
}
}

this my code, getting error that gerServerSideProps cannot be used in app direc, ive searched but i cannot find what i can do to get the context, because NextPageContext and getServerSideProps, both are used in page router, so is there any way i can do it with the app directory

2 Replies

Avatar
Ray
you could use getServerSession from next-auth
https://next-auth.js.org/configuration/nextjs#in-app-router
Avatar
Black-headed GullOP
can u rewrite the code with the auth options parameter