B
B
BonBon Slick2021-10-18 03:44:54
redux
BonBon Slick, 2021-10-18 03:44:54

How to properly invalidate state modules after exit?

Vuex, the state contains a lot of information on various modules, for example:
1 - authentication status
2 - user details, configurations and settings
3 - forms so that the user can continue typing from where he left off (I know that here it is necessary to synchronize with the API in ideally, but so far only on the client)
4 - other, additional info for reactivity

It turns out that when we log out, we need to clean a lot of modules or make a global reset.
Each module has 2 methods
1 - reset = resets everything to the default state, of course, even if there were changes in the fields
2 - clear - resets data by type, string = '', json = '{}', int = 0 and so on , depending on how the method is implemented

It's one thing when there are up to 10 modules, another when there are 25, 30+ of them, it already becomes cumbersome to write all these methods and follow them, call them after the logout. Since only a part of the states, modules is cleaned, for example, the list of pictures on the main page can be left so as not to pull the API again, even though this is a controversial matter, because after the logout the user conditionally resets preferences, but then anyway, many sites use cookies for tracking requests for recommendations.

It is possible that to simplify the development, it will be easier to throw everything off globally while I am thinking.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-18
@BonBonSlick

Well, add a type property to each module with a default on and when logout, just loop through the modules. __logoutAction: 'reset' | 'none' | 'clear''none'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question