-
-
Save frankitox/3a0306ad3f2fa078767314d59930810c to your computer and use it in GitHub Desktop.
auth0 w/hooks
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
(ns myapp | |
(:require | |
[react] | |
[reagent.core :as r] | |
[reagent.dom :as rd] | |
["@auth0/auth0-react" :as auth0])) | |
(def origin (.-origin (.-location js/window))) | |
(defn hello-world [] | |
(let [{:keys [isLoading error isAuthenticated user logout loginWithRedirect]} | |
(-> (.useAuth0 auth0) (js->clj :keywordize-keys true))] | |
[:div | |
(cond | |
isLoading [:div "Loading..."] | |
error [:div "Oops..." (.-message error)] | |
isAuthenticated [:div "Hello " (:name user) " " | |
[:button {:on-click #(logout #js {:returnTo origin})} | |
"Logout"]]) | |
[:p "Hello times"] | |
[:button {:on-click loginWithRedirect} | |
"Click"]])) | |
(defn mountit [] | |
(rd/render [:> (.-Auth0Provider auth0) | |
{:domain "" | |
:clientId "" | |
:redirectUri origin} | |
[:f> hello-world]] | |
(.getElementById js/document "root"))) | |
(defn init [] | |
(mountit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment