From c2de1009ff53543eb459016ffd1c9521708cb52d Mon Sep 17 00:00:00 2001 From: Keagan Date: Wed, 15 Apr 2026 18:21:35 +0200 Subject: [PATCH 1/2] fixed google auth hash --- src/source/routes/google_user.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/source/routes/google_user.clj b/src/source/routes/google_user.clj index e24c311..605970e 100644 --- a/src/source/routes/google_user.clj +++ b/src/source/routes/google_user.clj @@ -5,7 +5,8 @@ [source.db.honey :as hon] [source.password :as pw] [source.email.templates :as templates] - [source.email.gmail :as gmail])) + [source.email.gmail :as gmail] + [source.db.util :as db.util])) (defn get {:summary "completes the google oauth2 flow and returns the authenticated user" @@ -42,6 +43,7 @@ (do (hon/insert! ds {:tname :users :data {:email email + :email-hash (pw/hash-password email) :type user-type}}) (let [new-user (hon/find-one ds {:tname :users :where [:= :email email]}) From 1e8e006b67d2b587516bd8101c85f62658f83a95 Mon Sep 17 00:00:00 2001 From: Keagan Date: Thu, 16 Apr 2026 08:59:52 +0200 Subject: [PATCH 2/2] added hella logs to the google auth flow and email verification --- src/source/routes/google_user.clj | 37 ++++++++++++++++++++++++++++--- src/source/routes/user.clj | 7 +++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/source/routes/google_user.clj b/src/source/routes/google_user.clj index 605970e..69fad54 100644 --- a/src/source/routes/google_user.clj +++ b/src/source/routes/google_user.clj @@ -5,8 +5,7 @@ [source.db.honey :as hon] [source.password :as pw] [source.email.templates :as templates] - [source.email.gmail :as gmail] - [source.db.util :as db.util])) + [source.email.gmail :as gmail])) (defn get {:summary "completes the google oauth2 flow and returns the authenticated user" @@ -32,25 +31,57 @@ (let [{:keys [uuid _uri]} body email (google/google-session-user uuid (:params req)) + _ (prn "email from google" email) user (hon/find-one ds {:tname :users :where [:= :email email]}) - user-type (get-in req [:cookies "user_type" :value])] + _ (prn "try find user, got:" user) + user-type (get-in req [:cookies "user_type" :value]) + _ (prn "user-type" user-type)] (if (some? user) (let [payload (dissoc user :password) session (auth/create-session payload)] + (prn "found a user, sending response") (res/response (merge {:user payload} session))) (do + (prn "no user, inserting user with email hash" email (pw/hash-password email) user-type) (hon/insert! ds {:tname :users :data {:email email :email-hash (pw/hash-password email) :type user-type}}) + (prn "inserted user") (let [new-user (hon/find-one ds {:tname :users :where [:= :email email]}) + _ (prn "retrieved new user" new-user) payload (dissoc new-user :password) + _ (prn "user without password" payload) session (auth/create-session payload)] + (prn "session" session) + (prn "going to send email with" (pw/hash-password email) "to" email) (gmail/send-email {:to email :subject "Source - Verify your email" :body (templates/email-verification {:email-hash (pw/hash-password email)}) :type :text/html}) + (prn "sent email with" (pw/hash-password email) "to" email) (res/response (merge {:user payload} session))))))) + +(comment + (require '[source.db.util :as db.util]) + + (def ds (db.util/conn)) + (hon/insert! ds {:tname :users + :data {:email "merv@simply.co.za" + :email-hash (pw/hash-password "merv@simply.co.za") + :type "creator"}}) + (hon/find-one ds {:tname :users + :where [:= :email "merv@simply.co.za"]}) + (let [new-user (hon/find-one ds {:tname :users + :where [:= :email "merv@simply.co.za"]}) + payload (dissoc new-user :password) + session (auth/create-session payload)] + #_(gmail/send-email {:to email + :subject "Source - Verify your email" + :body (templates/email-verification {:email-hash (pw/hash-password email)}) + :type :text/html}) + (res/response (merge {:user payload} session))) + ()) diff --git a/src/source/routes/user.clj b/src/source/routes/user.clj index 173f48c..cb60f9c 100644 --- a/src/source/routes/user.clj +++ b/src/source/routes/user.clj @@ -74,14 +74,19 @@ 403 {:body (api/response-schema)}}} [{:keys [ds path-params]}] (let [email-hash (:hash path-params) + _ (prn "email hash from path params" email-hash) user (hon/find-one ds {:tname :users - :where [:= :email-hash email-hash]})] + :where [:= :email-hash email-hash]}) + _ (prn "found user by email hash" user)] (if (some? user) (do + (prn "a user exists, updating user details") (hon/update! ds {:tname :users :where [:= :id (:id user)] :data {:email-verified 1 :email-hash ""}}) + (prn "user has been updated") + (prn "running redirect") (-> (conf/read-value :cors-origin) (str "/dashboard/onboarding") (res/redirect)))