Skip to content

I can't fetch the data from getServerSideProps? #1502

Discussion options

You must be logged in to vote

So there are several problems here.

You wrote /challenge, but you probably meant /api/challenge instead.

Also, you shouldn't call a Next.js API route from inside getServerSideProps, just use the logic directly! (meaning, you can use getSession directly inside getServerSideProps).

To access the session client-side, you can use the built-in useSession() hook.

Use the Provider React Context provider to share (cache) the session between useSession() calls. You can control how often you want to fetch the session from the API. Check out the options: https://next-auth.js.org/getting-started/client#options

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alexandredev3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1499 on March 11, 2021 20:34.