Last active
February 21, 2021 14:41
-
-
Save thatanjan/8bddc62b3866e2b226a28b03c1225fa1 to your computer and use it in GitHub Desktop.
Redirect in nextjs from server side.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getServerSideProps = async () => { | |
// check if the user is logged in | |
const ifAuthenticated = false | |
if (ifAuthenticated) { | |
return { redirect: { destination: '/login', permanent: false } } | |
} | |
return { props: {} } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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