thingco / shared-frontend-libs

0 stars 0 forks source link

Feat/enhance authenticated hook #72

Closed DanCouper closed 3 years ago

DanCouper commented 3 years ago

Added a selector for states that are accessible while a user is authenticated.

Add a selector function isInStateAccessibleWhileAuthenticated (only for use internally, not exposed, hence the verbose name) that checks against a (typed) set of states for matches.

If one of the matches returns true, then can assume still authed. All of these states shouldn't really move a user into an unauthorised state -- so for example useLoggingOut: the program isn't actually unauthorised when in that state, it is only after another action is sent.

This fixes the issue of losing the place in the navigation: prior to the change, moving from profile screen to loggingOut state would have mean de-authorising. Then if a user cancels, they go back to the dashboard instead of the profile page.

By keeping them authed, the loggingOut state can be described using a modal/view in the profile section.

This also applies (currently) to the changePasswordInput and changePinInput states.