mirror of
https://github.com/penpot/penpot.git
synced 2025-06-14 21:21:38 +02:00
🎉 Add authentication with google.
This commit is contained in:
parent
5268a7663f
commit
19cd84597d
23 changed files with 589 additions and 276 deletions
|
@ -5,7 +5,7 @@
|
|||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.main.data.auth
|
||||
(:require
|
||||
|
@ -34,7 +34,7 @@
|
|||
(watch [this state stream]
|
||||
(let [team-id (:default-team-id data)]
|
||||
(rx/of (du/profile-fetched data)
|
||||
(rt/navigate :dashboard-team {:team-id team-id}))))))
|
||||
(rt/nav :dashboard-team {:team-id team-id}))))))
|
||||
|
||||
;; --- Login
|
||||
|
||||
|
@ -63,6 +63,20 @@
|
|||
(on-error err)
|
||||
(rx/empty)))
|
||||
(rx/map logged-in))))))
|
||||
|
||||
(defn login-from-token
|
||||
[{:keys [profile] :as tdata}]
|
||||
(ptk/reify ::login-from-token
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(merge state (dissoc initial-state :route :router)))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [this state s]
|
||||
(let [team-id (:default-team-id profile)]
|
||||
(rx/of (du/profile-fetched profile)
|
||||
(rt/nav' :dashboard-team {:team-id team-id}))))))
|
||||
|
||||
;; --- Logout
|
||||
|
||||
(def clear-user-data
|
||||
|
|
|
@ -62,6 +62,12 @@
|
|||
([id] (mutation id {}))
|
||||
([id params] (mutation id params)))
|
||||
|
||||
(defmethod mutation :login-with-google
|
||||
[id params]
|
||||
(let [url (str url "/api/oauth/google")]
|
||||
(->> (http/send! {:method :post :url url})
|
||||
(rx/mapcat handle-response))))
|
||||
|
||||
(defmethod mutation :upload-image
|
||||
[id params]
|
||||
(let [form (js/FormData.)]
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
[beicon.core :as rx]
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.data.auth :as da]
|
||||
[uxbox.main.data.users :as du]
|
||||
[uxbox.main.data.messages :as dm]
|
||||
[uxbox.main.store :as st]
|
||||
|
@ -66,6 +67,10 @@
|
|||
(st/emit! (rt/nav :settings-profile)
|
||||
du/fetch-profile)))
|
||||
|
||||
(defn- handle-authentication
|
||||
[tdata]
|
||||
(st/emit! (da/login-from-token tdata)))
|
||||
|
||||
(mf/defc verify-token
|
||||
[{:keys [route] :as props}]
|
||||
(let [token (get-in route [:query-params :token])]
|
||||
|
@ -73,10 +78,11 @@
|
|||
(fn []
|
||||
(->> (rp/mutation :verify-profile-token {:token token})
|
||||
(rx/subs
|
||||
(fn [response]
|
||||
(case (:type response)
|
||||
:verify-email (handle-email-verified response)
|
||||
:change-email (handle-email-changed response)
|
||||
(fn [tdata]
|
||||
(case (:type tdata)
|
||||
:verify-email (handle-email-verified tdata)
|
||||
:change-email (handle-email-changed tdata)
|
||||
:authentication (handle-authentication tdata)
|
||||
nil))
|
||||
(fn [error]
|
||||
(case (:code error)
|
||||
|
|
|
@ -10,13 +10,16 @@
|
|||
(ns uxbox.main.ui.auth.login
|
||||
(:require
|
||||
[cljs.spec.alpha :as s]
|
||||
[beicon.core :as rx]
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.data.auth :as da]
|
||||
[uxbox.main.repo :as rp]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.data.messages :as dm]
|
||||
[uxbox.main.ui.components.forms :refer [input submit-button form]]
|
||||
[uxbox.util.object :as obj]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.forms :as fm]
|
||||
[uxbox.util.i18n :refer [tr t]]
|
||||
|
@ -38,6 +41,13 @@
|
|||
{:on-error (partial on-error form)})]
|
||||
(st/emit! (da/login params))))
|
||||
|
||||
(defn- login-with-google
|
||||
[event]
|
||||
(dom/prevent-default event)
|
||||
(->> (rp/mutation! :login-with-google {})
|
||||
(rx/subs (fn [{:keys [redirect-uri] :as rsp}]
|
||||
(.replace js/location redirect-uri)))))
|
||||
|
||||
(mf/defc login-form
|
||||
[{:keys [locale] :as props}]
|
||||
[:& form {:on-submit on-submit
|
||||
|
@ -60,6 +70,7 @@
|
|||
|
||||
(mf/defc login-page
|
||||
[{:keys [locale] :as props}]
|
||||
|
||||
[:div.generic-form.login-form
|
||||
[:div.form-container
|
||||
[:h1 (t locale "auth.login-title")]
|
||||
|
@ -67,6 +78,10 @@
|
|||
|
||||
[:& login-form {:locale locale}]
|
||||
|
||||
[:a.btn-secondary.btn-large.btn-google-auth
|
||||
{:on-click login-with-google}
|
||||
"Login with google"]
|
||||
|
||||
[:div.links
|
||||
[:div.link-entry
|
||||
[:a {:on-click #(st/emit! (rt/nav :auth-recovery-request))
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
;; 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/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.main.ui.settings.header
|
||||
|
@ -55,21 +58,3 @@
|
|||
{:class "foobar"
|
||||
:on-click #(st/emit! (rt/nav :settings-profile))}
|
||||
(t locale "settings.teams")]]]))
|
||||
|
||||
|
||||
|
||||
|
||||
;; [:div.main-logo
|
||||
;; {:on-click #(st/emit! (rt/nav :dashboard-team {:team-id team-id}))}
|
||||
;; i/logo-icon]
|
||||
;; [:section.main-bar
|
||||
;; [:nav
|
||||
;; [:a.nav-item
|
||||
;; {:class (when profile? "current")
|
||||
;; :on-click #(st/emit! (rt/nav :settings-profile))}
|
||||
;; (t locale "settings.profile")]
|
||||
;; [:a.nav-item
|
||||
;; {:class (when password? "current")
|
||||
;; :on-click #(st/emit! (rt/nav :settings-password))}
|
||||
;; (t locale "settings.password")]]]]))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue