Benefits of different client side useSession() implementations #2801
-
Question 💬Hey there,
. This results in the following questions for me:
If someone could clarify this, that would be much appreciated! Thanks in advance. How to reproduce ☕️Example code snippets are provided in the linked documentation. Contributing 🙌🏽Yes, I am willing to help answer this question in a PR |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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:
it's up to you to decide which approach makes most sense to you |
Beta Was this translation helpful? Give feedback.
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: