mirror of
https://github.com/penpot/penpot.git
synced 2025-06-10 20:01:37 +02:00
🐛 Fix bad redirect on new oops page with social login
This commit is contained in:
parent
017aad6454
commit
229eeae6db
5 changed files with 154 additions and 50 deletions
|
@ -168,13 +168,21 @@
|
||||||
accepting invitation, or third party auth signup or singin."
|
accepting invitation, or third party auth signup or singin."
|
||||||
[profile]
|
[profile]
|
||||||
(letfn [(get-redirect-events []
|
(letfn [(get-redirect-events []
|
||||||
(let [team-id (get-current-team-id profile)
|
(let [team-id (get-current-team-id profile)
|
||||||
welcome-file-id (get-in profile [:props :welcome-file-id])]
|
welcome-file-id (dm/get-in profile [:props :welcome-file-id])
|
||||||
(if (some? welcome-file-id)
|
redirect-href (:login-redirect @s/session)]
|
||||||
(rx/of
|
(cond
|
||||||
(rt/nav' :workspace {:project-id (:default-project-id profile)
|
(some? redirect-href)
|
||||||
:file-id welcome-file-id})
|
(binding [s/*sync* true]
|
||||||
(update-profile-props {:welcome-file-id nil}))
|
(swap! s/session dissoc :login-redirect)
|
||||||
|
(rx/of (rt/nav-raw :href redirect-href)))
|
||||||
|
|
||||||
|
(some? welcome-file-id)
|
||||||
|
(rx/of (rt/nav' :workspace {:project-id (:default-project-id profile)
|
||||||
|
:file-id welcome-file-id})
|
||||||
|
(update-profile-props {:welcome-file-id nil}))
|
||||||
|
|
||||||
|
:else
|
||||||
(rx/of (rt/nav' :dashboard-projects {:team-id team-id})))))]
|
(rx/of (rt/nav' :dashboard-projects {:team-id team-id})))))]
|
||||||
|
|
||||||
(ptk/reify ::logged-in
|
(ptk/reify ::logged-in
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
[app.util.i18n :refer [tr]]
|
[app.util.i18n :refer [tr]]
|
||||||
[app.util.keyboard :as k]
|
[app.util.keyboard :as k]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
|
[app.util.storage :as s]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
|
@ -47,10 +48,21 @@
|
||||||
(defn- login-with-oidc
|
(defn- login-with-oidc
|
||||||
[event provider params]
|
[event provider params]
|
||||||
(dom/prevent-default event)
|
(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)))
|
||||||
|
|
||||||
|
;; FIXME: this code should be probably moved outside of the UI
|
||||||
(->> (rp/cmd! :login-with-oidc (assoc params :provider provider))
|
(->> (rp/cmd! :login-with-oidc (assoc params :provider provider))
|
||||||
(rx/subs! (fn [{:keys [redirect-uri] :as rsp}]
|
(rx/subs! (fn [{:keys [redirect-uri] :as rsp}]
|
||||||
(if redirect-uri
|
(if redirect-uri
|
||||||
(.replace js/location redirect-uri)
|
(st/emit! (rt/nav-raw :uri redirect-uri))
|
||||||
(log/error :hint "unexpected response from OIDC method"
|
(log/error :hint "unexpected response from OIDC method"
|
||||||
:resp (pr-str rsp))))
|
:resp (pr-str rsp))))
|
||||||
(fn [cause]
|
(fn [cause]
|
||||||
|
|
|
@ -118,7 +118,8 @@
|
||||||
[:div {:class (stl/css :logo-title)} (tr "labels.login")]
|
[:div {:class (stl/css :logo-title)} (tr "labels.login")]
|
||||||
[:div {:class (stl/css :logo-subtitle)} (tr "not-found.login.free")]
|
[:div {:class (stl/css :logo-subtitle)} (tr "not-found.login.free")]
|
||||||
[:& login-methods {:on-recovery-request set-section-recovery
|
[:& login-methods {:on-recovery-request set-section-recovery
|
||||||
:on-success-callback success-login}]
|
:on-success-callback success-login
|
||||||
|
:params {:save-login-redirect true}}]
|
||||||
[:hr {:class (stl/css :separator)}]
|
[:hr {:class (stl/css :separator)}]
|
||||||
[:div {:class (stl/css :change-section)}
|
[:div {:class (stl/css :change-section)}
|
||||||
(tr "auth.register")
|
(tr "auth.register")
|
||||||
|
|
|
@ -151,11 +151,20 @@
|
||||||
(set! (.-href globals/location) "/"))
|
(set! (.-href globals/location) "/"))
|
||||||
|
|
||||||
(defn nav-raw
|
(defn nav-raw
|
||||||
[href]
|
[& {:keys [href uri]}]
|
||||||
(ptk/reify ::nav-raw
|
(ptk/reify ::nav-raw
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ _ _]
|
(effect [_ _ _]
|
||||||
(set! (.-href globals/location) href))))
|
(cond
|
||||||
|
(string? uri)
|
||||||
|
(.replace globals/location uri)
|
||||||
|
|
||||||
|
(string? href)
|
||||||
|
(set! (.-href globals/location) href)))))
|
||||||
|
|
||||||
|
(defn get-current-href
|
||||||
|
[]
|
||||||
|
(.-href globals/location))
|
||||||
|
|
||||||
(defn get-current-path
|
(defn get-current-path
|
||||||
[]
|
[]
|
||||||
|
@ -164,6 +173,7 @@
|
||||||
(subs hash 1)
|
(subs hash 1)
|
||||||
hash)))
|
hash)))
|
||||||
|
|
||||||
|
|
||||||
;; --- History API
|
;; --- History API
|
||||||
|
|
||||||
(defn initialize-history
|
(defn initialize-history
|
||||||
|
|
|
@ -10,75 +10,148 @@
|
||||||
[app.common.transit :as t]
|
[app.common.transit :as t]
|
||||||
[app.util.functions :as fns]
|
[app.util.functions :as fns]
|
||||||
[app.util.globals :as g]
|
[app.util.globals :as g]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]
|
||||||
|
[okulary.util :as ou]))
|
||||||
|
|
||||||
;; Using ex/ignoring because can receive a DOMException like this when
|
;; Using ex/ignoring because can receive a DOMException like this when
|
||||||
;; importing the code as a library: Failed to read the 'localStorage'
|
;; importing the code as a library: Failed to read the 'localStorage'
|
||||||
;; property from 'Window': Storage is disabled inside 'data:' URLs.
|
;; property from 'Window': Storage is disabled inside 'data:' URLs.
|
||||||
(defonce ^:private local-storage
|
(defonce ^:private local-storage-backend
|
||||||
(ex/ignoring (unchecked-get g/global "localStorage")))
|
(ex/ignoring (unchecked-get g/global "localStorage")))
|
||||||
|
|
||||||
|
(defonce ^:private session-storage-backend
|
||||||
|
(ex/ignoring (unchecked-get g/global "sessionStorage")))
|
||||||
|
|
||||||
|
(def ^:dynamic *sync*
|
||||||
|
"Dynamic variable which determines the mode of operation of the
|
||||||
|
storage mutatio actions. By default is asynchronous."
|
||||||
|
false)
|
||||||
|
|
||||||
(defn- encode-key
|
(defn- encode-key
|
||||||
[k]
|
[prefix k]
|
||||||
(assert (keyword? k) "key must be keyword")
|
(assert (keyword? k) "key must be keyword")
|
||||||
(let [kns (namespace k)
|
(let [kns (namespace k)
|
||||||
kn (name k)]
|
kn (name k)]
|
||||||
(str "penpot:" kns "/" kn)))
|
(str prefix ":" kns "/" kn)))
|
||||||
|
|
||||||
(defn- decode-key
|
(defn- decode-key
|
||||||
[k]
|
[prefix k]
|
||||||
(when (str/starts-with? k "penpot:")
|
(when (str/starts-with? k prefix)
|
||||||
(let [k (subs k 7)]
|
(let [l (+ (count prefix) 1)
|
||||||
|
k (subs k l)]
|
||||||
(if (str/starts-with? k "/")
|
(if (str/starts-with? k "/")
|
||||||
(keyword (subs k 1))
|
(keyword (subs k 1))
|
||||||
(let [[kns kn] (str/split k "/" 2)]
|
(let [[kns kn] (str/split k "/" 2)]
|
||||||
(keyword kns kn))))))
|
(keyword kns kn))))))
|
||||||
|
|
||||||
(defn- lookup-by-index
|
(defn- lookup-by-index
|
||||||
[result index]
|
[backend prefix result index]
|
||||||
(try
|
(try
|
||||||
(let [key (.key ^js local-storage index)
|
(let [key (.key ^js backend index)
|
||||||
key' (decode-key key)]
|
key' (decode-key prefix key)]
|
||||||
(if key'
|
(if key'
|
||||||
(let [val (.getItem ^js local-storage key)]
|
(let [val (.getItem ^js backend key)]
|
||||||
(assoc! result key' (t/decode-str val)))
|
(assoc! result key' (t/decode-str val)))
|
||||||
result))
|
result))
|
||||||
(catch :default _
|
(catch :default _
|
||||||
result)))
|
result)))
|
||||||
|
|
||||||
(defn- load
|
(defn- load-data
|
||||||
[]
|
[backend prefix]
|
||||||
(when (some? local-storage)
|
(if (some? backend)
|
||||||
(let [length (.-length ^js local-storage)]
|
(let [length (.-length ^js backend)]
|
||||||
(loop [index 0
|
(loop [index 0
|
||||||
result (transient {})]
|
result (transient {})]
|
||||||
(if (< index length)
|
(if (< index length)
|
||||||
(recur (inc index)
|
(recur (inc index)
|
||||||
(lookup-by-index result index))
|
(lookup-by-index backend prefix result index))
|
||||||
(persistent! result))))))
|
(persistent! result))))
|
||||||
|
{}))
|
||||||
|
|
||||||
(defonce ^:private latest-state (load))
|
(defn create-storage
|
||||||
|
[backend prefix]
|
||||||
|
(let [initial (load-data backend prefix)
|
||||||
|
curr-data #js {:content initial}
|
||||||
|
last-data #js {:content initial}
|
||||||
|
watches (js/Map.)
|
||||||
|
|
||||||
(defn- on-change*
|
update-key
|
||||||
[curr-state]
|
(fn [key val]
|
||||||
(let [prev-state latest-state]
|
(when (some? backend)
|
||||||
(try
|
(if (some? val)
|
||||||
(run! (fn [key]
|
(.setItem ^js backend (encode-key prefix key) (t/encode-str val))
|
||||||
(let [prev-val (get prev-state key)
|
(.removeItem ^js backend (encode-key prefix key)))))
|
||||||
curr-val (get curr-state key)]
|
|
||||||
(when-not (identical? curr-val prev-val)
|
|
||||||
(if (some? curr-val)
|
|
||||||
(.setItem ^js local-storage (encode-key key) (t/encode-str curr-val))
|
|
||||||
(.removeItem ^js local-storage (encode-key key))))))
|
|
||||||
(into #{} (concat (keys curr-state)
|
|
||||||
(keys prev-state))))
|
|
||||||
(finally
|
|
||||||
(set! latest-state curr-state)))))
|
|
||||||
|
|
||||||
(defonce on-change
|
on-change*
|
||||||
(fns/debounce on-change* 2000))
|
(fn [curr-state]
|
||||||
|
(let [prev-state (unchecked-get last-data "content")]
|
||||||
|
(try
|
||||||
|
(run! (fn [key]
|
||||||
|
(let [prev-val (get prev-state key)
|
||||||
|
curr-val (get curr-state key)]
|
||||||
|
(when-not (identical? curr-val prev-val)
|
||||||
|
(update-key key curr-val))))
|
||||||
|
(into #{} (concat (keys curr-state)
|
||||||
|
(keys prev-state))))
|
||||||
|
(finally
|
||||||
|
(unchecked-set last-data "content" curr-state)))))
|
||||||
|
|
||||||
(defonce storage (atom latest-state))
|
on-change
|
||||||
(add-watch storage :persistence
|
(fns/debounce on-change* 2000)]
|
||||||
(fn [_ _ _ curr-state]
|
|
||||||
(on-change curr-state)))
|
(reify
|
||||||
|
IAtom
|
||||||
|
|
||||||
|
IDeref
|
||||||
|
(-deref [_] (unchecked-get curr-data "content"))
|
||||||
|
|
||||||
|
ILookup
|
||||||
|
(-lookup [coll k]
|
||||||
|
(-lookup coll k nil))
|
||||||
|
(-lookup [_ k not-found]
|
||||||
|
(let [state (unchecked-get curr-data "content")]
|
||||||
|
(-lookup state k not-found)))
|
||||||
|
|
||||||
|
IReset
|
||||||
|
(-reset! [self newval]
|
||||||
|
(let [oldval (unchecked-get curr-data "content")]
|
||||||
|
(unchecked-set curr-data "content" newval)
|
||||||
|
(if *sync*
|
||||||
|
(on-change* newval)
|
||||||
|
(on-change newval))
|
||||||
|
(when (> (.-size watches) 0)
|
||||||
|
(-notify-watches self oldval newval))
|
||||||
|
newval))
|
||||||
|
|
||||||
|
ISwap
|
||||||
|
(-swap! [self f]
|
||||||
|
(let [state (unchecked-get curr-data "content")]
|
||||||
|
(-reset! self (f state))))
|
||||||
|
(-swap! [self f x]
|
||||||
|
(let [state (unchecked-get curr-data "content")]
|
||||||
|
(-reset! self (f state x))))
|
||||||
|
(-swap! [self f x y]
|
||||||
|
(let [state (unchecked-get curr-data "content")]
|
||||||
|
(-reset! self (f state x y))))
|
||||||
|
(-swap! [self f x y more]
|
||||||
|
(let [state (unchecked-get curr-data "content")]
|
||||||
|
(-reset! self (apply f state x y more))))
|
||||||
|
|
||||||
|
IWatchable
|
||||||
|
(-notify-watches [self oldval newval]
|
||||||
|
(ou/doiter
|
||||||
|
(.entries watches)
|
||||||
|
(fn [n]
|
||||||
|
(let [f (aget n 1)
|
||||||
|
k (aget n 0)]
|
||||||
|
(f k self oldval newval)))))
|
||||||
|
|
||||||
|
(-add-watch [self key f]
|
||||||
|
(.set watches key f)
|
||||||
|
self)
|
||||||
|
|
||||||
|
(-remove-watch [_ key]
|
||||||
|
(.delete watches key)))))
|
||||||
|
|
||||||
|
(defonce storage (create-storage local-storage-backend "penpot"))
|
||||||
|
(defonce session (create-storage session-storage-backend "penpot"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue