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
I currently have SPA application. I want to check if the stores that hold user's tokens are set (currently, I have 2 of these but there maybe more in the future).
Currently, I do the checking in the root +layout.ts's load function: I check if the stores exist, if the tokens are not expired etc and I allow user to navigate or redirect him to login if something bad happens. Is this a good way to do it? I also subscribe to those stores in the +layout.ts file just before defining the load function and I never unsub from them because I don't know when/if I should do it.
Is this a good way of doing it? Is there a better way to do it?
I was thinking about using Navigation API/navigating store, but I don't know where should I subscribe to them (or add event listener for the API) as there is no single file that is run on the application start.
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
Uh oh!
There was an error while loading. Please reload this page.
-
I currently have SPA application. I want to check if the stores that hold user's tokens are set (currently, I have 2 of these but there maybe more in the future).
Currently, I do the checking in the root
+layout.ts
's load function: I check if the stores exist, if the tokens are not expired etc and I allow user to navigate or redirect him to login if something bad happens. Is this a good way to do it? I also subscribe to those stores in the+layout.ts
file just before defining theload
function and I never unsub from them because I don't know when/if I should do it.Is this a good way of doing it? Is there a better way to do it?
I was thinking about using Navigation API/
navigating
store, but I don't know where should I subscribe to them (or add event listener for the API) as there is no single file that is run on the application start.Beta Was this translation helpful? Give feedback.
All reactions