Skip to content

Instantly share code, notes, and snippets.

@thatanjan
Last active February 21, 2021 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatanjan/8bddc62b3866e2b226a28b03c1225fa1 to your computer and use it in GitHub Desktop.
Save thatanjan/8bddc62b3866e2b226a28b03c1225fa1 to your computer and use it in GitHub Desktop.
Redirect in nextjs from server side.
export const getServerSideProps = async () => {
// check if the user is logged in
const ifAuthenticated = false
if (ifAuthenticated) {
return { redirect: { destination: '/login', permanent: false } }
}
return { props: {} }
}
import { GetServerSideProps } from 'next'
export const getServerSideProps: GetServerSideProps = async () => {
// check if the user is logged in
const ifAuthenticated = false
if (ifAuthenticated) {
return { redirect: { destination: '/login', permanent: false } }
}
return { props: {} }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment