diff --git a/backend/src/app/rpc/mutations/verify_token.clj b/backend/src/app/rpc/mutations/verify_token.clj index 357983a23..e1af35591 100644 --- a/backend/src/app/rpc/mutations/verify_token.clj +++ b/backend/src/app/rpc/mutations/verify_token.clj @@ -44,20 +44,29 @@ claims) (defmethod process-token :verify-email - [{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}] - (let [profile (db/get-by-id conn :profile profile-id {:for-update true})] - (when (:is-active profile) - (ex/raise :type :validation - :code :email-already-validated)) - (when (not= (:email profile) - (:email claims)) - (ex/raise :type :validation - :code :invalid-token)) + [{:keys [conn session] :as cfg} _params {:keys [profile-id] :as claims}] + (let [profile (profile/retrieve-profile conn profile-id) + claims (assoc claims :profile profile)] + + (when-not (:is-active profile) + (when (not= (:email profile) + (:email claims)) + (ex/raise :type :validation + :code :invalid-token)) + + (db/update! conn :profile + {:is-active true} + {:id (:id profile)})) + + (with-meta claims + {:transform-response + (fn [request response] + (let [uagent (get-in request [:headers "user-agent"]) + id (session/create! session {:profile-id profile-id + :user-agent uagent})] + (assoc response + :cookies (session/cookies session {:value id}))))}))) - (db/update! conn :profile - {:is-active true} - {:id (:id profile)}) - claims)) (defmethod process-token :auth [{:keys [conn] :as cfg} _params {:keys [profile-id] :as claims}] diff --git a/frontend/src/app/main/ui/auth/verify_token.cljs b/frontend/src/app/main/ui/auth/verify_token.cljs index 670a1d4df..0f0136837 100644 --- a/frontend/src/app/main/ui/auth/verify_token.cljs +++ b/frontend/src/app/main/ui/auth/verify_token.cljs @@ -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) 2020 UXBOX Labs SL +;; Copyright (c) 2020-2021 UXBOX Labs SL (ns app.main.ui.auth.verify-token (:require @@ -21,9 +21,9 @@ [app.main.ui.auth.register :refer [register-page]] [app.main.ui.icons :as i] [app.util.forms :as fm] - [app.util.storage :refer [cache]] [app.util.i18n :as i18n :refer [tr t]] [app.util.router :as rt] + [app.util.storage :refer [cache]] [app.util.timers :as ts] [beicon.core :as rx] [cljs.spec.alpha :as s] @@ -35,7 +35,7 @@ [data] (let [msg (tr "dashboard.notifications.email-verified-successfully")] (ts/schedule 100 #(st/emit! (dm/success msg))) - (st/emit! (rt/nav :auth-login)))) + (st/emit! (da/login-from-token data)))) (defmethod handle-token :change-email [data]