Kicks the user out when their session expires.

This commit is contained in:
BC
2019-03-01 07:58:30 -08:00
parent 1fa6154f39
commit c726613ecc
5 changed files with 31 additions and 15 deletions

View File

@@ -43,5 +43,6 @@ services:
- DATOMIC_SQL_HOST=database - DATOMIC_SQL_HOST=database
ports: ports:
- 4334:4334 - 4334:4334
restart: on-failure

View File

@@ -46,7 +46,7 @@
(if (and token user) (if (and token user)
{:status 301 {:status 301
:headers {"Location" (str "/?jwt=" (jwt/sign (doto {:user (:name profile) :headers {"Location" (str "/?jwt=" (jwt/sign (doto {:user (:name profile)
:exp (time/plus (time/now) (time/days 7)) :exp (time/plus (time/now) (time/days 30))
:user/clients (map (fn [c] :user/clients (map (fn [c]
(dissoc c :client/bank-accounts )) (dissoc c :client/bank-accounts ))
(:user/clients user)) (:user/clients user))

View File

@@ -10,6 +10,7 @@
[clojure.walk :as walk] [clojure.walk :as walk]
[venia.core :as v] [venia.core :as v]
[auto-ap.history :as p] [auto-ap.history :as p]
[auto-ap.events :as events]
[pushy.core :as pushy])) [pushy.core :as pushy]))
(re-frame/reg-fx (re-frame/reg-fx
@@ -155,18 +156,25 @@
:body (when = (:post method) query) :body (when = (:post method) query)
:url (str "/api/graphql?query=" (when (= :get method) (js/encodeURIComponent query)) :url (str "/api/graphql?query=" (when (= :get method) (js/encodeURIComponent query))
"&variables=" (pr-str (or variables {})))}))] "&variables=" (pr-str (or variables {})))}))]
(if (>= (:status response) 400) (cond
(= (:status response) 401)
(re-frame/dispatch [::events/logout "Your session has expired. Please log in again."])
(>= (:status response) 400)
(when on-error (when on-error
(->> response (->> response
:body :body
:errors :errors
(dates->date-times) (dates->date-times)
(map #(assoc % :status (:status response))) (map #(assoc % :status (:status response)))
(conj on-error) (conj on-error)
(re-frame/dispatch))) (re-frame/dispatch)))
:else
(->> response (->> response
:body :body
:data :data
(dates->date-times) (dates->date-times)
(conj on-success) (conj on-success)
(re-frame/dispatch))))))) (re-frame/dispatch)))))))

View File

@@ -164,9 +164,10 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::logout ::logout
(fn [{:keys [db]} [_]] (fn [{:keys [db]} [_ logout-reason]]
{:db (assoc db :user nil :menu {:client {:active? false} {:db (assoc db :user nil :menu {:client {:active? false}
:account {:active? false}}) :account {:active? false}}
:logout-reason logout-reason)
:redirect (bidi/path-for routes/routes :login) :redirect (bidi/path-for routes/routes :login)
:set-local-storage ["jwt" nil]})) :set-local-storage ["jwt" nil]}))

View File

@@ -9,12 +9,18 @@
[auto-ap.routes :as routes] [auto-ap.routes :as routes]
[bidi.bidi :as bidi])) [bidi.bidi :as bidi]))
(re-frame/reg-sub
::logout-reason
(fn [db] (-> db :logout-reason)))
(defn login-page [] (defn login-page []
[:div.container [:div.container
[:section.is-fullheight.hero [:section.is-fullheight.hero
[:div.hero-body [:div.hero-body
[:div.container [:div.container
[:div.column.is-4.is-offset-4.has-text-centered [:div.column.is-4.is-offset-4.has-text-centered
(when-let [reason @(re-frame/subscribe [::logout-reason])]
[:div.notification.is-warning reason])
[:h1.title "Login"] [:h1.title "Login"]
[:div.box.slideInFromBelow [:div.box.slideInFromBelow