Auto-redirect from app to login on 403
This commit is contained in:
parent
388bb3fb7d
commit
23591952b8
29 changed files with 60 additions and 40 deletions
|
|
@ -1,4 +1 @@
|
|||
(ns ^{:doc "Field-level authorisation. Messy."
|
||||
:author "Simon Brooke"}
|
||||
youyesyet.authorisation
|
||||
(:require [youyesyet.env :refer [defaults]]))
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue