This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix navigation bugs ocurring with session profiles
[Re #47]
- Loading branch information
Damian Hryniewicz
committed
Aug 31, 2021
1 parent
1562d16
commit cc810ba
Showing
15 changed files
with
272 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<namespace>>.client.navigation | ||
(:require <<#hydrogen-ssr?>>[pushy.core :as pushy] | ||
[secretary.core :as secretary] | ||
<</hydrogen-ssr?>><<#hydrogen-session-keycloak?>>[clojure.string :as str] | ||
<</hydrogen-session-keycloak?>>[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?>><<^hydrogen-ssr?>> | ||
|
||
(defn redirect! [loc] | ||
(set! (.-location js/window) loc))<</hydrogen-ssr?>> | ||
|
||
(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="))))<</hydrogen-session-keycloak?>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<namespace>>.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] | ||
[<<namespace>>.client.theme :as theme] | ||
[<<namespace>>.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]) |
Oops, something went wrong.