Get context in App Directory
Unanswered
Black-headed Gull posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
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
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](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
you could use
https://next-auth.js.org/configuration/nextjs#in-app-router
getServerSession
from next-authhttps://next-auth.js.org/configuration/nextjs#in-app-router
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Black-headed GullOP
can u rewrite the code with the auth options parameter