Get context in App Directory
Unanswered
Black-headed Gull posted this in #help-forum
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
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
Black-headed GullOP
can u rewrite the code with the auth options parameter