You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my app the user get assigned a temporary session as long as she is not logged it.
The sessions id needs to be handed to all the fetchers as an argument (which will end up in a header).
When the user logs in, she gets a new a new session id as the response and this has then to be used across all fetchers. So for "hystorical raisons" each get/post request needs a session id header param, even when logging in (using a temporary session UUID created on the client).
As a tricky bonus the /order endpoint can be used with either a temporary or user session ID.
I would also like to prevent swr from fetching /user if the session ID is temporary and not a user session (which is determined by the session response containing user field).
functionuseSession(){const{data: session, mutate }=useSWR("/session")asyncfunctionlogin(email,password){// Here it must use the temp session idconstloginSession=awaitpost("/login",session.id,{ email, password })mutate(loginSession)}return{
session,
login,
logout
}}functionuseUser(){const{ session, logout }=useSession()const{data: user}=useSWR(session.user ? ["/user",session.id] : null,get)return{
user,
logout,}}functionuseOrder(){const{ session }=useSession()const{data: order}=useSWR(["/order, session.id], get)
return{
order
}}
I am struggling to find out when to create the temp session UUID and how to make the switch to the user session ID once she logged it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my app the user get assigned a temporary session as long as she is not logged it.
The sessions id needs to be handed to all the fetchers as an argument (which will end up in a header).
When the user logs in, she gets a new a new session id as the response and this has then to be used across all fetchers. So for "hystorical raisons" each get/post request needs a session id header param, even when logging in (using a temporary session UUID created on the client).
As a tricky bonus the
/order
endpoint can be used with either a temporary or user session ID.I would also like to prevent swr from fetching
/user
if the session ID is temporary and not a user session (which is determined by the session response containinguser
field).I am struggling to find out when to create the temp session UUID and how to make the switch to the user session ID once she logged it.
Beta Was this translation helpful? Give feedback.
All reactions