Skip to content

Instantly share code, notes, and snippets.

@frankitox
Created February 19, 2021 19:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankitox/3a0306ad3f2fa078767314d59930810c to your computer and use it in GitHub Desktop.
Save frankitox/3a0306ad3f2fa078767314d59930810c to your computer and use it in GitHub Desktop.
auth0 w/hooks
(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