Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Refactor session profiles' :go-to event handling #38

Open
werenall opened this issue Dec 19, 2020 · 0 comments
Open

Refactor session profiles' :go-to event handling #38

werenall opened this issue Dec 19, 2020 · 0 comments

Comments

@werenall
Copy link
Contributor

As for now session profiles have a :go-to event handler and :go-to* event handler.
The former is responsible for making sure that the application has enough data to perform an authentication check if needed. As soon as that's true, a :go-to* is dispatch.
That one was, up until now, responsible for doing authorization checks (e.g. landing only for non-authenticated users) and, if authorization checks has passed, letting through the actual navigation event.

So that alone would already cry for further division into two handlers - one for authorization and one for navigation. But naming event registrations were blockers here. I really wanted to outermost one to be called :go-to as that's the intention to do.

Recently I realized that it's very much doable nicely with help of re-frame async flow. That :go-to event could look somewhat like this (untested!):

(rf/reg-event-fx
  :go-to
  (fn [_ _]
    {:async-flow
     {:first-dispatch [::ensure-authentication]
      :rules [{:when :seen?
               :events ::ensure-authentication.success
               :dispatch [::ensure-authorization]}
              {:when :seen?
               :events ::ensure-authorization.success
               :dispatch [::go-to*]
               :halt? true}
              {:when :seen-any-of?
               :events [::ensure-authentication.fail ::ensure-authorization.fail]
               :dispatch [:go-to.fail]
               :halt? true}]}}))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant