Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

redirect if not logged in next js

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

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

  return {
    props: { session }
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #redirect #logged #js
ADD COMMENT
Topic
Name
2+6 =