Skip to content
Discussion options

You must be logged in to vote

Using API routes is pretty straight forward in most cases. one request in, one response out. Everything is sequential.

Clientside is a bit trickier, because you don't know the user's interaction before hand, you don't know when they make a request to the authenticated part of your app!

For this reason, we cache the session in-memory (in a single React state, nothing fancy) that you receive from the backend.

That state is then reused several times. This means you don't have to make expensive calls to check the session every time. This cache has to be populated somehow though. You have two options:

  1. use getServerSideProps or getInitialProps to receive a session BEFORE the page loads, and pa…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lukvermeulen
Comment options

@balazsorban44
Comment options

Answer selected by lukvermeulen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
question Ask how to do something or how something works
2 participants
Converted from issue

This discussion was converted from issue #2800 on September 20, 2021 14:54.