|
@@ -17,24 +17,24 @@
|
|
|
|
|
|
(defn sign-out!
|
|
(defn sign-out!
|
|
[]
|
|
[]
|
|
- (try (.signOut js/LSAmplify.Auth)
|
|
|
|
|
|
+ (try (.signOut js/LSAuth.Auth)
|
|
(catch :default e (js/console.warn e))))
|
|
(catch :default e (js/console.warn e))))
|
|
|
|
|
|
-(defn- setup-configure!
|
|
|
|
|
|
+(defn setup-configure!
|
|
[]
|
|
[]
|
|
#_:clj-kondo/ignore
|
|
#_:clj-kondo/ignore
|
|
- (def setupAuthConfigure! (.-setupAuthConfigure js/LSAmplify))
|
|
|
|
|
|
+ (defn setupAuthConfigure! [config]
|
|
|
|
+ (.init js/LSAuth (bean/->js {:authCognito (merge config {:loginWith {:email true}})})))
|
|
#_:clj-kondo/ignore
|
|
#_:clj-kondo/ignore
|
|
(def LSAuthenticator
|
|
(def LSAuthenticator
|
|
- (adapt-class (.-LSAuthenticator js/LSAmplify)))
|
|
|
|
|
|
+ (adapt-class (.-LSAuthenticator js/LSAuth)))
|
|
|
|
|
|
- (.setLanguage js/LSAmplify.I18n (or (:preferred-language @state/state) "en"))
|
|
|
|
(setupAuthConfigure!
|
|
(setupAuthConfigure!
|
|
- #js {:region config/REGION,
|
|
|
|
- :userPoolId config/USER-POOL-ID,
|
|
|
|
- :userPoolWebClientId config/COGNITO-CLIENT-ID,
|
|
|
|
- :identityPoolId config/IDENTITY-POOL-ID,
|
|
|
|
- :oauthDomain config/OAUTH-DOMAIN}))
|
|
|
|
|
|
+ {:region config/REGION,
|
|
|
|
+ :userPoolId config/USER-POOL-ID,
|
|
|
|
+ :userPoolClientId config/COGNITO-CLIENT-ID,
|
|
|
|
+ :identityPoolId config/IDENTITY-POOL-ID,
|
|
|
|
+ :oauthDomain config/OAUTH-DOMAIN}))
|
|
|
|
|
|
(rum/defc user-pane
|
|
(rum/defc user-pane
|
|
[_sign-out! user]
|
|
[_sign-out! user]
|
|
@@ -55,45 +55,22 @@
|
|
|
|
|
|
(rum/defc page-impl
|
|
(rum/defc page-impl
|
|
[]
|
|
[]
|
|
- (let [[ready?, set-ready?] (rum/use-state false)
|
|
|
|
- [tab, set-tab!] (rum/use-state :login)
|
|
|
|
- *ref-el (rum/use-ref nil)]
|
|
|
|
-
|
|
|
|
- (hooks/use-effect!
|
|
|
|
- (fn [] (setup-configure!)
|
|
|
|
- (set-ready? true)
|
|
|
|
- (js/setTimeout
|
|
|
|
- (fn []
|
|
|
|
- (when-let [^js el (some-> (rum/deref *ref-el) (.querySelector ".amplify-tabs"))]
|
|
|
|
- (let [btn1 (.querySelector el "button")]
|
|
|
|
- (.addEventListener el "pointerdown"
|
|
|
|
- (fn [^js e]
|
|
|
|
- (if (= (.-target e) btn1)
|
|
|
|
- (set-tab! :login)
|
|
|
|
- (set-tab! :create-account)))))))))
|
|
|
|
- [])
|
|
|
|
-
|
|
|
|
- (hooks/use-effect!
|
|
|
|
- (fn []
|
|
|
|
- (when-let [^js el (rum/deref *ref-el)]
|
|
|
|
- (js/setTimeout
|
|
|
|
- #(some-> (.querySelector el (str "input[name=" (if (= tab :login) "username" "email") "]"))
|
|
|
|
- (.focus)) 100)))
|
|
|
|
- [tab])
|
|
|
|
|
|
+ (let [*ref-el (rum/use-ref nil)]
|
|
|
|
|
|
[:div.cp__user-login
|
|
[:div.cp__user-login
|
|
{:ref *ref-el}
|
|
{:ref *ref-el}
|
|
- (when ready?
|
|
|
|
- (LSAuthenticator
|
|
|
|
- {:termsLink "https://blog.logseq.com/terms/"}
|
|
|
|
- (fn [^js op]
|
|
|
|
- (let [sign-out!' (.-signOut op)
|
|
|
|
- ^js user-proxy (.-user op)
|
|
|
|
- ^js user (try (js/JSON.parse (js/JSON.stringify user-proxy))
|
|
|
|
- (catch js/Error e
|
|
|
|
- (js/console.error "Error: Amplify user payload:" e)))
|
|
|
|
- user' (bean/->clj user)]
|
|
|
|
- (user-pane sign-out!' user')))))]))
|
|
|
|
|
|
+ (LSAuthenticator
|
|
|
|
+ {:titleRender (fn [tab]
|
|
|
|
+ (shui/card-header
|
|
|
|
+ {:class "px-0"}
|
|
|
|
+ (shui/card-title
|
|
|
|
+ {:class "capitalize"}
|
|
|
|
+ (string/replace tab "-" " "))))
|
|
|
|
+ :onSessionCallback #()}
|
|
|
|
+ (fn [^js op]
|
|
|
|
+ (let [sign-out!' (.-signOut op)
|
|
|
|
+ user' (bean/->clj (.-sessionUser op))]
|
|
|
|
+ (user-pane sign-out!' user'))))]))
|
|
|
|
|
|
(rum/defcs modal-inner <
|
|
(rum/defcs modal-inner <
|
|
shortcut/disable-all-shortcuts
|
|
shortcut/disable-all-shortcuts
|
|
@@ -109,7 +86,7 @@
|
|
(shui/dialog-open!
|
|
(shui/dialog-open!
|
|
(fn [_close] (modal-inner))
|
|
(fn [_close] (modal-inner))
|
|
{:label "user-login"
|
|
{:label "user-login"
|
|
- :content-props {:onPointerDownOutside #(let [inputs (sel "form[data-amplify-form] input:not([type=checkbox])")
|
|
|
|
|
|
+ :content-props {:onPointerDownOutside #(let [inputs (sel ".ls-authenticator-content form input:not([type=checkbox])")
|
|
inputs (some->> inputs (map (fn [^js e] (.-value e))) (remove string/blank?))]
|
|
inputs (some->> inputs (map (fn [^js e] (.-value e))) (remove string/blank?))]
|
|
(when (seq inputs)
|
|
(when (seq inputs)
|
|
(.preventDefault %)))}}))
|
|
(.preventDefault %)))}}))
|