Plaid can now be linked by clients.

This commit is contained in:
2022-07-21 08:21:16 -07:00
parent 746787df79
commit b214a527fa
12 changed files with 259 additions and 33 deletions

View File

@@ -4,11 +4,12 @@
[auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by]]
[auto-ap.views.utils :refer [with-user]]
[auto-ap.views.utils :refer [with-user parse-jwt]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[goog.crypt.base64 :as b64]
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]
[goog.crypt.base64 :as base64]))
(defn jwt->data [token]
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
@@ -142,12 +143,20 @@
(re-frame/reg-event-fx
::set-active-route
(fn [{:keys [db]} [_ handler params route-params]]
(println (:user/role (parse-jwt (:user db))))
(cond
(and (not= :login handler) (not (:user db)))
{:redirect (bidi/path-for routes/routes :login)
:db (assoc db :active-route :login
:active-page :login
:page-failure nil)}
(and (not= "admin" (:user/role (parse-jwt (:user db))))
(str/includes? (name handler) "admin"))
{:redirect (bidi/path-for routes/routes :index)
:db (assoc db :active-route :index
:active-page :index
:page-failure nil)}
:else
{:db (-> db
(assoc :active-route handler