Replies: 2 comments
-
I would create the session once in the first component or even before rendering React, and then read it from context, I believe most of the time the sessions is pretty static and doesn't really change, except when you logout, right? Context would work for that, but if you can, somehow, get the session info from the API in a get request I would create a useSession hook using SWR to get the session data (this is what I usually do, to get the current user from the API) |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help. What makes this flow even worse is that the server can timeout logged in users sessions. In that case the user would have to re-login (or we read the login credentials from a secure storage in the react native app). |
Beta Was this translation helpful? Give feedback.
-
I have several custom hooks that all depend on
useSession()
to annotate the key with the session token.However at the apps start a new session should be created via
post
inside (?)useSession()
hook:There are several problems with that:
useSession()
trigger the creation of a new session, so multiple sessions are created on the servertempId
to not trigger a fetch before the session is createdWhat is the correct way to start and sync up such interconnected hooks?
Beta Was this translation helpful? Give feedback.
All reactions