Auto-redirect from app to login on 403

This commit is contained in:
Simon Brooke 2018-09-23 14:19:32 +01:00
parent 388bb3fb7d
commit 23591952b8
29 changed files with 60 additions and 40 deletions

View file

@ -1,4 +1 @@
(ns ^{:doc "Field-level authorisation. Messy."
:author "Simon Brooke"}
youyesyet.authorisation
(:require [youyesyet.env :refer [defaults]]))

View file

@ -51,6 +51,16 @@
:anchor nil))
(defn handle-forbidden
"If response has status 403 (forbidden) redirect to the login page."
[response & forms]
(if
(= (str (:status response)) "403")
(do
(js/console.log "Forbidden! redirecting")
(set! (.-location js/document) "/login"))
(apply 'do forms)))
(defn compose-packet
[item]
"Convert this `item` into a URI which can be sent as a GET call"
@ -197,10 +207,12 @@
;; TODO: signal something has failed? It doesn't matter very much, unless it keeps failing.
(js/console.log (str "Failed to fetch locality data" response))
;; loop to do it again
(dispatch [:dispatch-later [{:ms 60000 :dispatch [:fetch-locality]}]])
{:db (assoc
(remove-from-feedback db :fetch-locality)
:error (cons :fetch-locality (:error db)))}))
(handle-forbidden
response
(dispatch [:dispatch-later [{:ms 60000 :dispatch [:fetch-locality]}]])
{:db (assoc
(remove-from-feedback db :fetch-locality)
:error (cons :fetch-locality (:error db)))})))
(reg-event-fx