From cc810ba90f642cc1aaccdd14c85f2dbfb17f2734 Mon Sep 17 00:00:00 2001 From: Damian Hryniewicz Date: Tue, 31 Aug 2021 13:35:53 +0200 Subject: [PATCH] Fix navigation bugs ocurring with session profiles [Re #47] --- resources/core/api/util.clj | 5 +- resources/core/cljs/client.cljs | 5 +- resources/core/cljs/home.cljs | 5 +- resources/core/cljs/navigation.cljs | 65 +++++++++++ resources/core/cljs/routes.cljs | 6 +- resources/core/cljs/view.cljs | 49 +------- resources/session/cognito/cljs/landing.cljs | 6 +- resources/session/cognito/cljs/session.cljs | 2 +- resources/session/keycloak/cljs/landing.cljs | 2 +- resources/session/keycloak/cljs/session.cljs | 16 +-- resources/ssr/client_substitutes/landing.clj | 65 +++++++++++ resources/ssr/cljs/navigation.cljs | 61 ---------- resources/ssr/ssr/root.clj | 115 +++++++++++++++---- src/hydrogen/core/duct_template.clj | 3 +- src/hydrogen/ssr/duct_template.clj | 24 +++- 15 files changed, 272 insertions(+), 157 deletions(-) create mode 100644 resources/core/cljs/navigation.cljs create mode 100644 resources/ssr/client_substitutes/landing.clj delete mode 100644 resources/ssr/cljs/navigation.cljs diff --git a/resources/core/api/util.clj b/resources/core/api/util.clj index 7de56b8..593ea0a 100644 --- a/resources/core/api/util.clj +++ b/resources/core/api/util.clj @@ -21,4 +21,7 @@ (defn wrap-authentication-required [handler auth-middleware] (-> handler (wrap-routes restrict-fn) - (wrap-routes auth-middleware)))<> + (wrap-routes auth-middleware))) + +(defn wrap-authentication [handler auth-middleware] + (wrap-routes handler auth-middleware))<> diff --git a/resources/core/cljs/client.cljs b/resources/core/cljs/client.cljs index efab6a2..da8a584 100644 --- a/resources/core/cljs/client.cljs +++ b/resources/core/cljs/client.cljs @@ -10,7 +10,8 @@ [re-frame.core :as rf] [reagent.dom :as rd] [<>.client.breadcrumbs :as breadcrumbs] - [<>.client.home :as home]<<#hydrogen-session?>> + [<>.client.home :as home] + [<>.client.navigation :as navigation]<<#hydrogen-session?>> [<>.client.landing :as landing]<> [<>.client.routes :as routes]<<#hydrogen-session-keycloak?>> [<>.client.session]<> @@ -104,6 +105,6 @@ (defn ^:export init [] (dev-setup) (rf/dispatch-sync [::load-app])<<#hydrogen-session-keycloak?>> - (view/fix-query-params js/location.hash)<> + (navigation/fix-query-params js/location.hash)<> (routes/app-routes) (mount-root)) diff --git a/resources/core/cljs/home.cljs b/resources/core/cljs/home.cljs index 8c6ddbb..1c50f9f 100644 --- a/resources/core/cljs/home.cljs +++ b/resources/core/cljs/home.cljs @@ -8,7 +8,8 @@ [<>.client.breadcrumbs :as breadcrumbs]<<#hydrogen-session?>> [<>.client.session :as session] [<>.client.user :as user]<> - [<>.client.view :as view])) + [<>.client.view :as view] + [<>.client.navigation :as navigation])) (rf/reg-event-fx ::view.enter @@ -34,7 +35,7 @@ (defn- logout [] [:div.logout {:on-click #(do (rf/dispatch [::session/user-logout]) - (view/redirect! "/#/landing"))} + (navigation/redirect! "/#/landing"))} "Logout"])<> (defn main [] diff --git a/resources/core/cljs/navigation.cljs b/resources/core/cljs/navigation.cljs new file mode 100644 index 0000000..3a7beea --- /dev/null +++ b/resources/core/cljs/navigation.cljs @@ -0,0 +1,65 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/ + +{{=<< >>=}} +(ns <>.client.navigation + (:require <<#hydrogen-ssr?>>[pushy.core :as pushy] + [secretary.core :as secretary] + <><<#hydrogen-session-keycloak?>>[clojure.string :as str] + <>[re-frame.core :as rf]))<<#hydrogen-ssr?>> + +(def history (pushy/pushy secretary/dispatch! + (fn [x] (when (secretary/locate-route x) x)))) + +(defn redirect! [path] + (pushy/set-token! history path)) + +(defn start! + "Start navigation's event listeners (to process links and such)" + [] + (pushy/start! history))<><<^hydrogen-ssr?>> + +(defn redirect! [loc] + (set! (.-location js/window) loc))<> + +(rf/reg-fx + :redirect + (fn [loc] + (redirect! loc)))<<#hydrogen-session-keycloak?>> + +(defn remove-query-param [loc-hash param] + (let [[path query-params] (str/split loc-hash #"\?")] + (if query-params + (->> + (str/split query-params #"\&") + (remove + #(str/starts-with? % (str (name param) "="))) + (str/join "&") + (conj [path]) + (filter seq) + (str/join "?")) + path))) + +(defn get-query-param [loc-hash param] + (let [[_ query-params] (str/split loc-hash #"\?")] + (when query-params + (some-> + (some + #(when (str/starts-with? % (str (name param) "=")) %) + (str/split query-params #"\&")) + (str/split #"\=") + (second))))) + +(defn fix-query-params + "This function makes sure that query params list in location url + starts with a question mark instead of an ampersand. + + It assumes that the only scenario when this happens is when + keycloak appends its params necessary for the auth process + and when the first query param doesn't come with a ? instead of &: + `/foobar&state=...&session_state=...&code=...`." + [loc-hash] + (when (and (str/index-of loc-hash "&state=") + (not (str/index-of loc-hash "?"))) + (redirect! (str/replace loc-hash "&state=" "?state="))))<> diff --git a/resources/core/cljs/routes.cljs b/resources/core/cljs/routes.cljs index ea071d3..ca3d493 100644 --- a/resources/core/cljs/routes.cljs +++ b/resources/core/cljs/routes.cljs @@ -18,7 +18,7 @@ [<>.client.session :as session] [<>.client.user :as user] [<>.client.util :as util]<> - [<>.client.view :as view])) + [<>.client.navigation :as navigation])) (defn hook-browser-navigation! [] (doto (History.) @@ -203,7 +203,7 @@ (rf/dispatch [:go-to [::hydrogen-demo.shop-item/view item-id]])) (defroute "*" [] - (view/redirect! "/#/landing")) + (navigation/redirect! "/#/landing")) ;; -------------------- (hook-browser-navigation!))<><<^hydrogen-session?>> @@ -244,7 +244,7 @@ (rf/dispatch [:go-to [::hydrogen-demo.shop-item/view item-id]])) (defroute "*" [] - (view/redirect! "/#/home")) + (navigation/redirect! "/#/home")) ;; -------------------- (hook-browser-navigation!))<> diff --git a/resources/core/cljs/view.cljs b/resources/core/cljs/view.cljs index 7f4b340..8b8ae88 100644 --- a/resources/core/cljs/view.cljs +++ b/resources/core/cljs/view.cljs @@ -4,8 +4,7 @@ {{=<< >>=}} (ns <>.client.view - (:require <<#hydrogen-session-keycloak?>>[clojure.string :as str] - <>[re-frame.core :as rf])) + (:require [re-frame.core :as rf])) (rf/reg-sub ::active-view @@ -17,14 +16,6 @@ (fn [db [_ active-view]] (assoc db :active-view active-view))) -(defn redirect! [loc] - (set! (.-location js/window) loc)) - -(rf/reg-fx - :redirect - (fn [loc] - (redirect! loc))) - (defmulti view-display #(when (vector? %) (first %))) (defmethod view-display :default @@ -35,40 +26,4 @@ [] (let [active-view (rf/subscribe [::active-view])] (fn [] - [view-display @active-view])))<<#hydrogen-session-keycloak?>> - -(defn remove-query-param [loc-hash param] - (let [[path query-params] (str/split loc-hash #"\?")] - (if query-params - (->> - (str/split query-params #"\&") - (remove - #(str/starts-with? % (str (name param) "="))) - (str/join "&") - (conj [path]) - (filter seq) - (str/join "?")) - path))) - -(defn get-query-param [loc-hash param] - (let [[_ query-params] (str/split loc-hash #"\?")] - (when query-params - (some-> - (some - #(when (str/starts-with? % (str (name param) "=")) %) - (str/split query-params #"\&")) - (str/split #"\=") - (second))))) - -(defn fix-query-params - "This function makes sure that query params list in location url - starts with a question mark instead of an ampersand. - - It assumes that the only scenario when this happens is when - keycloak appends its params necessary for the auth process - and when the first query param doesn't come with a ? instead of &: - `localhost/#/foobar&state=...&session_state=...&code=...`." - [loc-hash] - (when (and (str/index-of loc-hash "&state=") - (not (str/index-of loc-hash "?"))) - (redirect! (str/replace loc-hash "&state=" "?state="))))<> + [view-display @active-view]))) diff --git a/resources/session/cognito/cljs/landing.cljs b/resources/session/cognito/cljs/landing.cljs index daf46d9..a77db24 100644 --- a/resources/session/cognito/cljs/landing.cljs +++ b/resources/session/cognito/cljs/landing.cljs @@ -5,7 +5,7 @@ {{=<< >>=}} (ns <>.client.landing (:require [re-frame.core :as rf] - [reagent.core :as reagent] + [reagent.core :as r] [<>.client.session :as session] [<>.client.theme :as theme] [<>.client.view :as view])) @@ -14,14 +14,14 @@ ::view.enter (fn [_ _] {:dispatch [::view/set-active-view [::view]] - :redirect "/#/landing"})) + :redirect "/<<^hydrogen-ssr?>>#/<>landing"})) (rf/reg-event-fx ::view.leave (fn [_ _] {})) -(def credentials (reagent/atom {:username "" :password ""})) +(def credentials (r/atom {:username "" :password ""})) (defn swap-input! [event atom field] (swap! atom assoc field (.. event -target -value))) diff --git a/resources/session/cognito/cljs/session.cljs b/resources/session/cognito/cljs/session.cljs index b280fe7..780a2d7 100644 --- a/resources/session/cognito/cljs/session.cljs +++ b/resources/session/cognito/cljs/session.cljs @@ -162,7 +162,7 @@ (fn [_ _] {:dispatch-n [[::set-token-and-schedule-refresh] [::set-auth-error nil]] - :redirect "/#/home"})) + :redirect "/<<^hydrogen-ssr?>>#/<>home"})) (rf/reg-fx ::do-user-login diff --git a/resources/session/keycloak/cljs/landing.cljs b/resources/session/keycloak/cljs/landing.cljs index ca943b3..4759a0f 100644 --- a/resources/session/keycloak/cljs/landing.cljs +++ b/resources/session/keycloak/cljs/landing.cljs @@ -13,7 +13,7 @@ ::view.enter (fn [_ _] {:dispatch [::view/set-active-view [::view]] - :redirect "/#/home"})) + :redirect "/<<^hydrogen-ssr?>>#/<>home"})) (rf/reg-event-fx ::view.leave diff --git a/resources/session/keycloak/cljs/session.cljs b/resources/session/keycloak/cljs/session.cljs index 0c2289d..b5b6441 100644 --- a/resources/session/keycloak/cljs/session.cljs +++ b/resources/session/keycloak/cljs/session.cljs @@ -7,7 +7,7 @@ (:require [clojure.spec.alpha :as s] [re-frame.core :as rf] [<>.client.session.oidc-sso :as oidc-sso] - [<>.client.view :as view])) + [<>.client.navigation :as navigation])) ;; Keycloak Javascript library is not designed to be used in a ;; functional way. When you create a keycloak object to interact with @@ -32,9 +32,9 @@ (or (nil? @keycloak) (and - (view/get-query-param js/location.hash "state") - (view/get-query-param js/location.hash "session_state") - (view/get-query-param js/location.hash "code")))) + (navigation/get-query-param js/location.hash "state") + (navigation/get-query-param js/location.hash "session_state") + (navigation/get-query-param js/location.hash "code")))) (rf/reg-event-fx ::set-auth-error @@ -143,9 +143,9 @@ (defn- remove-keycloak-process-query-params [location-hash] (-> location-hash - (view/remove-query-param :state) - (view/remove-query-param :code) - (view/remove-query-param :session_state))) + (navigation/remove-query-param :state) + (navigation/remove-query-param :code) + (navigation/remove-query-param :session_state))) (rf/reg-event-fx ::on-login-success @@ -171,7 +171,7 @@ (handle-keycloak-obj-change keycloak-obj) ;; Since we sometime turn &state into ?state, Keycloak ;; is unable to clean up after itself. - (view/redirect! (remove-keycloak-process-query-params js/location.hash))))) + (navigation/redirect! (remove-keycloak-process-query-params js/location.hash))))) (.catch #(rf/dispatch [::set-auth-error "Failed to initialize Keycloak"])))))) (rf/reg-fx diff --git a/resources/ssr/client_substitutes/landing.clj b/resources/ssr/client_substitutes/landing.clj new file mode 100644 index 0000000..bd6324d --- /dev/null +++ b/resources/ssr/client_substitutes/landing.clj @@ -0,0 +1,65 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/ + +{{=<< >>=}} +(ns <>.client.landing + "This namespace is there to solve cross-platform compatibility for BE and FE when doing isomorphic rendering" + (:require [re-frame.core :as rf] + [<>.client.theme :as theme] + [<>.client.view :as view])) + +(rf/reg-event-fx + ::view.enter + (fn [_ _] + {:dispatch [::view/set-active-view [::view]] + :redirect "/landing"})) + +(rf/reg-event-fx + ::view.leave + (fn [_ _] + {})) + +(def credentials (atom {:username "" :password ""})) + +(defn swap-input! [event atom field] + (swap! atom assoc field (.. event -target -value))) + +(defn login-form [] + [:div.login-form-container + [:form.login-form + [:div.form-field + [:img.form-field__icon {:src "images/email-address.svg"}] + [:input.form-field__input + {:type "email" + :auto-complete "username" + :placeholder "Email" + :id "email" + :value (:username @credentials) + :on-change #(swap-input! % credentials :username)}]] + [:div.form-field + [:img.form-field__icon {:src "images/password.svg"}] + [:input.form-field__input + {:type "password" + :auto-complete "current-password" + :placeholder "Password" + :id "password" + :value (:password @credentials) + :on-change #(swap-input! % credentials :password)}]]] + [:button.btn.btn--gradient "Login"]]) + +(defn header [] + [:header + [:h1 "Hydrogen"]]) + +(defn main [] + (let [theme (rf/subscribe [::theme/get-theme])] + (fn [] + [:div.landing-container + {:class (str "theme-" (name @theme))} + [header] + [login-form]]))) + +(defmethod view/view-display ::view + [_] + [main]) diff --git a/resources/ssr/cljs/navigation.cljs b/resources/ssr/cljs/navigation.cljs deleted file mode 100644 index a5a4a87..0000000 --- a/resources/ssr/cljs/navigation.cljs +++ /dev/null @@ -1,61 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/ - -{{=<< >>=}} -(ns <>.client.navigation - (:require [pushy.core :as pushy] - [re-frame.core :as rf] - [secretary.core :as secretary])) - -(def history (pushy/pushy secretary/dispatch! - (fn [x] (when (secretary/locate-route x) x)))) - -(defn redirect! [path] - (pushy/set-token! history path)) - -(defn start! - "Start navigation's event listeners (to process links and such)" - [] - (pushy/start! history)) - -(rf/reg-fx - :redirect - (fn [path] - (redirect! path)))<<#hydrogen-session-keycloak?>> - -(defn remove-query-param [loc-hash param] - (let [[path query-params] (str/split loc-hash #"\?")] - (if query-params - (->> - (str/split query-params #"\&") - (remove - #(str/starts-with? % (str (name param) "="))) - (str/join "&") - (conj [path]) - (filter seq) - (str/join "?")) - path))) - -(defn get-query-param [loc-hash param] - (let [[_ query-params] (str/split loc-hash #"\?")] - (when query-params - (some-> - (some - #(when (str/starts-with? % (str (name param) "=")) %) - (str/split query-params #"\&")) - (str/split #"\=") - (second))))) - -(defn fix-query-params - "This function makes sure that query params list in location url - starts with a question mark instead of an ampersand. - - It assumes that the only scenario when this happens is when - keycloak appends its params necessary for the auth process - and when the first query param doesn't come with a ? instead of &: - `localhost/foobar&state=...&session_state=...&code=...`." - [loc-hash] - (when (and (str/index-of loc-hash "&state=") - (not (str/index-of loc-hash "?"))) - (redirect! (str/replace loc-hash "&state=" "?state="))))<> diff --git a/resources/ssr/ssr/root.clj b/resources/ssr/ssr/root.clj index 489094a..b6cdd09 100644 --- a/resources/ssr/ssr/root.clj +++ b/resources/ssr/ssr/root.clj @@ -5,17 +5,20 @@ {{=<< >>=}} (ns <>.ssr.root (:require [cognitect.transit :as transit] - [compojure.core :refer [context GET routes]] + [compojure.core :refer [context wrap-routes GET routes]] [hiccup.util :refer [as-str]] [hiccup.util :refer [escape-html as-str raw-string]] [hiccup2.core :refer [html]] [integrant.core :as ig] [re-frame.core :as rf] [re-frame.db :as rf.db] + [<>.api.util :as api-util] [<>.client.breadcrumbs :as client.breadcrumbs] [<>.client.home :as client.home] [<>.client.hydrogen-demo.shop :as client.shop] - [<>.client.hydrogen-demo.shop-item :as client.shop-item] + [<>.client.hydrogen-demo.shop-item :as client.shop-item]<<#hydrogen-session?>> + [buddy.auth :refer [authenticated?]] + [<>.client.landing :as client.landing]<> [<>.client.sidebar :as client.sidebar] [<>.client.theme :as client.theme] [<>.client.view :as client.view] @@ -59,7 +62,14 @@ :rel "shortcut icon" :type "image/x-icon"}] [:link {:href "https://fonts.googleapis.com/css?family=Poppins:400,700" :rel "stylesheet"}] - [:link {:rel "stylesheet" :href "/css/main.css"}]] + [:link {:rel "stylesheet" :href "/css/main.css"}]<<#hydrogen-session?>> + [:link {:rel "stylesheet" :href "/css/landing.css"}]<><<#hydrogen-session-cognito?>> + [:script {:src "https://cdn.jsdelivr.net/npm/amazon-cognito-identity-js@2.0.6/dist/amazon-cognito-identity.min.js" + :integrity "sha256-pYn9Yh/mq4hWZBz8ZKuFWmTWBBAsAwEDx0TjRZHZozc=" + :crossorigin "anonymous"}]<><<#hydrogen-session-keycloak?>> + [:script {:src "https://cdn.jsdelivr.net/npm/keycloak-js@9.0.0/dist/keycloak.min.js" + :integrity "sha256-cKzGXR7XoBTQp5rjJMHgTv72r1ERU266BypryyxzX2I=" + :crossorigin "anonymous"}]<>] [:script "var INITIAL_APP_DB;"] (some-> app-db (load-initial-app-db-script)) [:body @@ -72,7 +82,7 @@ (as-str))) ;; TODO use Teachascent's fork to make it work on multiple threads -;(defn- handle-route +;(defn- handle-route* ; [app-db] ; (let [db-id (util/uuid) ; result (with-bindings {#'re-frame.db/app-db-id db-id} @@ -81,12 +91,16 @@ ; (re-frame.db/clear-app-db db-id) ; result)) -(defn- handle-route +(defn- handle-route* ;; This solution will not work right with multiple clients asking for SSR as they will compete for the same resource. ;; Look at the solution above. [app-db] (reset! rf.db/app-db app-db) - (gen-html app-db)) + (gen-html app-db))<<^hydrogen-session?>> + +(defn- handle-route + [req {:keys [app-db]}] + (handle-route* app-db)) (defmethod ig/init-key :<>.ssr/root [_ _] ;; NOTE: this routes registry needs to be a ONE TO ONE matching in regards to client's app-routes @@ -94,23 +108,82 @@ (routes (GET "/home" req (handle-route - {:active-view [::client.home/view] - :breadcrumbs []})) + req + {:app-db + {:active-view [::client.home/view] + :breadcrumbs []}})) (GET "/shop" req (handle-route - {:active-view [::client.shop/view] - :shop {:items [:apple :orange :banana]} - :breadcrumbs [{:title "Home" :url "/home"} - {:title "Shop" :url "/shop" :disabled true}]})) + req + {:appp-db + {:active-view [::client.shop/view] + :shop {:items [:apple :orange :banana]} + :breadcrumbs [{:title "Home" :url "/home"} + {:title "Shop" :url "/shop" :disabled true}]}})) (GET "/shop/:id" [id :as req] (handle-route - (let [shop-item (srv.shop/get-shop-item id)] - {:active-view [::client.shop-item/view] - :breadcrumbs [{:title "Home" :url "/home"} - {:title "Shop" :url "/shop"} - {:title (:name shop-item) - :url (str "/" id) - :disabled true}] - :shop-item shop-item}))) + req + {:app-db + (let [shop-item (srv.shop/get-shop-item id)] + {:active-view [::client.shop-item/view] + :breadcrumbs [{:title "Home" :url "/home"} + {:title "Shop" :url "/shop"} + {:title (:name shop-item) + :url (str "/" id) + :disabled true}] + :shop-item shop-item})})) (GET "*" req - (handle-route {:error "I don't know where I am"}))))) + (handle-route + req + {:app-db {:error "I don't know where I am"}})))))<><<#hydrogen-session?>> + +(defn- handle-route + [req {:keys [app-db allow-unauthenticated? allow-authenticated?] + :or {allow-authenticated? true + allow-unauthenticated? false}}] + + (let [authenticated? (buddy.auth/authenticated? req) + authorised? (or (and authenticated? allow-authenticated?) + (and (not authenticated?) allow-unauthenticated?)) + app-db (if authorised? + app-db + {:error "Unnauthorised"})] + (handle-route* app-db))) + +(defmethod ig/init-key :<>.ssr/root [_ {:keys [auth-middleware]}] + ;; NOTE: this routes registry needs to be a ONE TO ONE matching in regards to client's app-routes + (context "/" [] + (-> + (routes + (GET "/home" req + (handle-route + req + {:app-db + {:active-view [::client.home/view] + :breadcrumbs []}})) + (GET "/shop" req + (handle-route + req + {:appp-db + {:active-view [::client.shop/view] + :shop {:items [:apple :orange :banana]} + :breadcrumbs [{:title "Home" :url "/home"} + {:title "Shop" :url "/shop" :disabled true}]}})) + (GET "/shop/:id" [id :as req] + (handle-route + req + {:app-db + (let [shop-item (srv.shop/get-shop-item id)] + {:active-view [::client.shop-item/view] + :breadcrumbs [{:title "Home" :url "/home"} + {:title "Shop" :url "/shop"} + {:title (:name shop-item) + :url (str "/" id) + :disabled true}] + :shop-item shop-item})})) + (GET "*" req + (handle-route + req + {:app-db {:error "I don't know where I am"} + :allow-unauthenticated? true}))) + (api-util/wrap-authentication auth-middleware))))<> diff --git a/src/hydrogen/core/duct_template.clj b/src/hydrogen/core/duct_template.clj index 471d49f..c4d4ba9 100644 --- a/src/hydrogen/core/duct_template.clj +++ b/src/hydrogen/core/duct_template.clj @@ -21,7 +21,8 @@ "src/{{dirs}}/client/util.cljs" (resource "core/cljs/util.cljs") "src/{{dirs}}/client/view.cljs" (resource "core/cljs/view.cljs") "src/{{dirs}}/client/hydrogen_demo/shop.cljs" (resource "core/cljs/hydrogen_demo/shop.cljs") - "src/{{dirs}}/client/hydrogen_demo/shop_item.cljs" (resource "core/cljs/hydrogen_demo/shop_item.cljs")})) + "src/{{dirs}}/client/hydrogen_demo/shop_item.cljs" (resource "core/cljs/hydrogen_demo/shop_item.cljs") + "src/{{dirs}}/client/navigation.cljs" (resource "core/cljs/navigation.cljs")})) (defn api-files [] diff --git a/src/hydrogen/ssr/duct_template.clj b/src/hydrogen/ssr/duct_template.clj index e21b337..6b9f06c 100644 --- a/src/hydrogen/ssr/duct_template.clj +++ b/src/hydrogen/ssr/duct_template.clj @@ -6,7 +6,7 @@ [] {"src/{{dirs}}/client.cljs" (resource "core/cljs/client.cljs") "src/{{dirs}}/client/routes.cljs" (resource "ssr/cljs/routes.cljs") - "src/{{dirs}}/client/navigation.cljs" (resource "ssr/cljs/navigation.cljs")}) + "src/{{dirs}}/client/navigation.cljs" (resource "core/cljs/navigation.cljs")}) (defn- cljc-templates [] @@ -30,17 +30,29 @@ "src/{{dirs}}/util/hiccup_parser.clj" (resource "ssr/util/hiccup_parser.clj") "test/{{dirs}}/util/hiccup_parser_test.clj" (resource "ssr/test/util/hiccup_parser_test.clj")} (utils/use-session-profile? profiles) - (merge {"src/{{dirs}}/client/home.clj" (resource "ssr/client_substitutes/home.clj")}))) + (merge {"src/{{dirs}}/client/home.clj" (resource "ssr/client_substitutes/home.clj") + "src/{{dirs}}/client/landing.clj" (resource "ssr/client_substitutes/landing.clj")}))) + +(defn routes-refs + [profiles] + (if (utils/use-session-profile? profiles) + ["api/config" + "api/example" + "api/user" + "ssr/root"] + ["api/config" + "api/example" + "ssr/root"])) (defn profile [{:keys [project-ns profiles]}] {:vars {:hydrogen-ssr? true - :cascading-routes (gen-cascading-routes project-ns ["api/config" - "api/example" - "ssr/root"])} + :cascading-routes (gen-cascading-routes project-ns (routes-refs profiles))} :templates (merge (cljs-templates) (cljc-templates) (other-templates profiles)) :deps '[[kibu/pushy "0.3.8"] [hiccup "2.0.0-alpha2"]] - :profile-base {(keyword (str project-ns ".ssr/root")) " {}"}}) + :profile-base {(keyword (str project-ns ".ssr/root")) (if (utils/use-session-profile? profiles) + " {:auth-middleware #ig/ref :duct.middleware.buddy/authentication}" + " {}")}})