Skip to content

Instantly share code, notes, and snippets.

@zendevil
Created July 7, 2021 18:50
Show Gist options
  • Save zendevil/3553c0b33fe30df0398dafc1c58b7603 to your computer and use it in GitHub Desktop.
Save zendevil/3553c0b33fe30df0398dafc1c58b7603 to your computer and use it in GitHub Desktop.
magic login
(defn login []
(let [
magic (Magic. "pk_live_E0A5A86F2EF4DE14"
(clj->js {:extensions [(OAuthExtension.)]}))
!social-logged-in (atom nil)
_ (go (js/console.log "is logged in " (<p! (.. magic -user (isLoggedIn))
)))
_ (go (reset! !social-logged-in
(<p! (.. magic -user (isLoggedIn))
)))
_ (js/console.log "social logged in " @!social-logged-in)
_ (go (js/console.log "redirect result"
@!social-logged-in
(<p! (.. magic -oauth (getRedirectResult)))))
]
[:div
(if @!social-logged-in
[:div {:style {:cursor :pointer}
:on-click #(.. magic -user (logout))} "Logout"]
[:div {:style {:display :flex :flex-direction :row}}
[:img
{:on-click (fn [event]
(go
(<p! (.. magic -oauth
(loginWithRedirect
#js {:provider "facebook"
:redirectURI
(.. js/window -location -origin)})))))
:src "https://i.stack.imgur.com/oL5c2.png"
:style {:cursor :pointer :height 50}}]])]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment