diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index f4ea04997..7f0d50e33 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -170,13 +170,16 @@ (letfn [(get-redirect-events [] (let [team-id (get-current-team-id profile) welcome-file-id (dm/get-in profile [:props :welcome-file-id]) - redirect-href (:login-redirect @s/session)] + redirect-href (:login-redirect @s/session) + current-href (rt/get-current-href)] (cond (some? redirect-href) (binding [s/*sync* true] (swap! s/session dissoc :login-redirect) - (rx/of (rt/nav-raw :href redirect-href))) + (if (= current-href redirect-href) + (rx/of (rt/reload true)) + (rx/of (rt/nav-raw :href redirect-href)))) (some? welcome-file-id) (rx/of (rt/nav' :workspace {:project-id (:default-project-id profile) diff --git a/frontend/src/app/main/ui/auth/login.cljs b/frontend/src/app/main/ui/auth/login.cljs index 5533a9171..901f0dd58 100644 --- a/frontend/src/app/main/ui/auth/login.cljs +++ b/frontend/src/app/main/ui/auth/login.cljs @@ -45,18 +45,22 @@ [] (st/emit! (du/create-demo-profile))) +(defn- store-login-redirect + [save-login-redirect] + (binding [s/*sync* true] + (if (some? save-login-redirect) + ;; Save the current login raw uri for later redirect user back to + ;; the same page, we need it to be synchronous because the user is + ;; going to be redirected instantly to the oidc provider uri + (swap! s/session assoc :login-redirect (rt/get-current-href)) + ;; Clean the login redirect + (swap! s/session dissoc :login-redirect)))) + (defn- login-with-oidc [event provider params] (dom/prevent-default event) - (binding [s/*sync* true] - (if (some? (:save-login-redirect params)) - ;; Save the current login raw uri for later redirect user back to - ;; the same page, we need it to be synchronous because the user is - ;; going to be redirected instantly to the oidc provider uri - (swap! s/session assoc :login-redirect (rt/get-current-href)) - ;; Clean the login redirect - (swap! s/session dissoc :login-redirect))) + (store-login-redirect (:save-login-redirect params)) ;; FIXME: this code should be probably moved outside of the UI (->> (rp/cmd! :login-with-oidc (assoc params :provider provider)) @@ -131,6 +135,7 @@ on-submit (mf/use-callback (fn [form _event] + (store-login-redirect (:save-login-redirect params)) (reset! error nil) (let [params (with-meta (:clean-data @form) {:on-error on-error diff --git a/frontend/src/app/util/timers.cljs b/frontend/src/app/util/timers.cljs index 6df8e2c3a..a1b1267cc 100644 --- a/frontend/src/app/util/timers.cljs +++ b/frontend/src/app/util/timers.cljs @@ -31,7 +31,7 @@ (defn asap [f] (-> (p/resolved nil) - (p/then f))) + (p/then (fn [_] (f))))) (defn interval [ms func]