Skip to content

Correct way to protect a page using getServerSideProps? #415

Answered by kmjennison
MattHeslington asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Matt, the code you provided should do what you're looking for: if a user is not authenticated, the server will return a redirect instead of the protected page.

Note that you don't have to provide an empty function. You can just do this:

export const getServerSideProps = withAuthUserSSR()()

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by MattHeslington
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants