0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

🐛 Fix unexpected redirect on invitation acceptation

This commit is contained in:
Andrey Antukh 2022-12-12 15:33:55 +01:00
parent 76a83bece9
commit 4e1e67fc3d
3 changed files with 13 additions and 26 deletions

View file

@ -60,6 +60,7 @@
(rx/merge
(rx/of (ev/initialize)
(du/initialize-profile))
(->> stream
(rx/filter du/profile-fetched?)
(rx/take 1)

View file

@ -164,6 +164,7 @@
(swap! storage dissoc :redirect-url)
(.replace js/location redirect-url))
(rt/nav' :dashboard-projects {:team-id team-id}))))]
(ptk/reify ::logged-in
IDeref
(-deref [_] profile)

View file

@ -10,9 +10,9 @@
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.users :as du]
[app.main.repo :as rp]
[app.main.store :as st]
[app.util.router :as rt]
[app.util.storage :refer [storage]]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]))
@ -93,32 +93,17 @@
(defn on-navigate
[router path]
(let [match (match-path router path)
profile (:profile @storage)
nopath? (or (= path "") (= path "/"))
path-name (-> match :data :name)
authpath? (some #(= path-name %) '(:auth-login
:auth-register
:auth-register-validate
:auth-register-success
:auth-recovery-request
:auth-recovery))
authed? (and (not (nil? profile))
(not= (:id profile) uuid/zero))]
(if-let [match (match-path router path)]
(st/emit! (rt/navigated match))
(cond
(or (and nopath? authed? (nil? match))
(and authpath? authed?))
(st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)}))
(and (not authed?) (nil? match))
;; We just recheck with an additional profile request; this avoids
;; some race conditions that causes unexpected redirects on
;; invitations workflows (and probably other cases).
(->> (rp/query! :profile)
(rx/subs (fn [{:keys [id] :as profile}]
(if (= id uuid/zero)
(st/emit! (rt/nav :auth-login))
(nil? match)
(st/emit! (rt/assign-exception {:type :not-found}))
:else
(st/emit! (rt/navigated match)))))
(st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)}))))))))
(defn init-routes
[]