mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 03:41:38 +02:00
Add authentication logic to the ui routing.
This commit is contained in:
parent
7318205b88
commit
41dac4bc7d
1 changed files with 36 additions and 21 deletions
|
@ -1,45 +1,60 @@
|
||||||
(ns uxbox.ui
|
(ns uxbox.ui
|
||||||
(:require [sablono.core :as html :refer-macros [html]]
|
(:require [sablono.core :as html :refer-macros [html]]
|
||||||
|
[promesa.core :as p]
|
||||||
[goog.dom :as gdom]
|
[goog.dom :as gdom]
|
||||||
[rum.core :as rum]
|
[rum.core :as rum]
|
||||||
[cats.labs.lens :as l]
|
[cats.labs.lens :as l]
|
||||||
[uxbox.state :as s]
|
[uxbox.state :as s]
|
||||||
|
[uxbox.router :as r]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.data.projects :as dp]
|
[uxbox.data.projects :as dp]
|
||||||
[uxbox.ui.lightbox :as ui.lb]
|
[uxbox.ui.lightbox :as ui-lightbox]
|
||||||
[uxbox.ui.users :as users]
|
[uxbox.ui.auth :as ui-auth]
|
||||||
[uxbox.ui.dashboard :as dashboard]
|
[uxbox.ui.dashboard :as ui-dashboard]
|
||||||
[uxbox.ui.workspace :refer (workspace)]
|
[uxbox.ui.workspace :refer (workspace)]
|
||||||
[uxbox.ui.mixins :as mx]
|
[uxbox.ui.mixins :as mx]
|
||||||
[uxbox.ui.shapes]))
|
[uxbox.ui.shapes]))
|
||||||
|
|
||||||
(def ^:static state
|
(def ^:const auth-data
|
||||||
(as-> (l/select-keys [:location :location-params]) $
|
(as-> (l/key :auth) $
|
||||||
(l/focus-atom $ s/state)))
|
(l/focus-atom $ s/state)))
|
||||||
|
|
||||||
|
(def ^:const +unrestricted+
|
||||||
|
#{:auth/login})
|
||||||
|
|
||||||
|
(def ^:const restricted?
|
||||||
|
(complement +unrestricted+))
|
||||||
|
|
||||||
(defn app-render
|
(defn app-render
|
||||||
[own]
|
[own]
|
||||||
(let [{:keys [location location-params] :as state} (rum/react state)]
|
(let [route (rum/react r/route-l)
|
||||||
(case location
|
auth (rum/react auth-data)
|
||||||
:auth/login (users/login)
|
location (:id route)
|
||||||
:dashboard/projects (dashboard/projects-page)
|
params (:params route)]
|
||||||
:dashboard/elements (dashboard/elements-page)
|
(if (and (restricted? location) (not auth))
|
||||||
:dashboard/icons (dashboard/icons-page)
|
(do (p/schedule 0 #(r/go :auth/login)) nil)
|
||||||
:dashboard/colors (dashboard/colors-page)
|
(case location
|
||||||
:workspace/page (let [projectid (:project-uuid location-params)
|
:auth/login (ui-auth/login)
|
||||||
pageid (:page-uuid location-params)]
|
:dashboard/projects (ui-dashboard/projects-page)
|
||||||
(workspace projectid pageid))
|
:dashboard/elements (ui-dashboard/elements-page)
|
||||||
nil
|
:dashboard/icons (ui-dashboard/icons-page)
|
||||||
)))
|
:dashboard/colors (ui-dashboard/colors-page)
|
||||||
|
:workspace/page (let [projectid (:project-uuid params)
|
||||||
|
pageid (:page-uuid params)]
|
||||||
|
(workspace projectid pageid))
|
||||||
|
nil
|
||||||
|
))))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(mx/component {:render app-render
|
(mx/component
|
||||||
:mixins [rum/reactive]
|
{:render app-render
|
||||||
:name "app"}))
|
:mixins [rum/reactive]
|
||||||
|
:name "app"}))
|
||||||
|
|
||||||
(defn init
|
(defn init
|
||||||
[]
|
[]
|
||||||
(println "ui/init")
|
(println "ui/init")
|
||||||
(let [app-dom (gdom/getElement "app")
|
(let [app-dom (gdom/getElement "app")
|
||||||
lb-dom (gdom/getElement "lightbox")]
|
lb-dom (gdom/getElement "lightbox")]
|
||||||
(rum/mount (app) app-dom)
|
(rum/mount (app) app-dom)
|
||||||
(rum/mount (ui.lb/lightbox) lb-dom)))
|
(rum/mount (ui-lightbox/lightbox) lb-dom)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue