🐛 Fix all the time redirect to login.

This commit is contained in:
Andrey Antukh 2020-12-22 16:23:23 +01:00
parent 7f8f8ecd62
commit 5636881463

View file

@ -11,6 +11,7 @@
(:require
[app.common.uuid :as uuid]
[app.common.spec :as us]
[app.main.repo :as rp]
[app.main.data.auth :refer [logout]]
[app.main.data.users :as udu]
[app.main.store :as st]
@ -51,10 +52,21 @@
(defn on-navigate
[router path]
(let [match (match-path router path)]
(let [match (match-path router path)
profile (:profile storage)
nopath? (or (= path "") (= path "/"))
authed? (and (not (nil? profile))
(not= (:id profile) uuid/zero))]
(cond
(or (= path "")
(nil? match))
(and nopath? authed? (nil? match))
(->> (rp/query! :profile)
(rx/subs (fn [profile]
(if (not= uuid/zero profile)
(st/emit! (rt/nav :dashboard-projects {:team-id (:default-team-id profile)}))
(st/emit! (rt/nav :auth-login))))))
(and (not authed?) (nil? match))
(st/emit! (rt/nav :auth-login))
(nil? match)