Browse Source

add username when publish

Tienson Qin 2 years ago
parent
commit
7acea49a6d
2 changed files with 10 additions and 1 deletions
  1. 4 1
      src/main/frontend/handler/publish.cljs
  2. 6 0
      src/main/frontend/handler/user.cljs

+ 4 - 1
src/main/frontend/handler/publish.cljs

@@ -16,6 +16,7 @@
             [frontend.util.fs :as fs-util]
             [frontend.util.page-property :as page-property]
             [frontend.handler.editor :as editor-handler]
+            [frontend.handler.user :as user-handler]
             [logseq.graph-parser.util.page-ref :as page-ref]
             [logseq.graph-parser.util :as gp-util]
             [medley.core :as medley]))
@@ -76,6 +77,7 @@
   [& {:keys [page-name]}]
   (state/set-state! [:ui/loading? :publish] true)
   (let [repo         (state/get-current-repo)
+        user-name    (user-handler/user-name)
         page-name    (or page-name
                          (state/get-current-page)
                          (date/today))
@@ -88,7 +90,8 @@
         {:keys [original-blocks blocks refs refed-blocks]} (transform-blocks page)
         embed-page-blocks (get-embed-pages original-blocks)
         body         (let [embed-page-blocks' (medley/map-vals :blocks embed-page-blocks)]
-                       {:page-id      page-id
+                       {:user-name    user-name
+                        :page-id      page-id
                         :blocks       blocks
                         :refed-blocks refed-blocks
                         :refs         refs

+ 6 - 0
src/main/frontend/handler/user.cljs

@@ -75,6 +75,12 @@
    parse-jwt
    :sub))
 
+(defn user-name []
+  (some->
+   (state/get-auth-id-token)
+   parse-jwt
+   :cognito:username))
+
 (defn logged-in? []
   (some? (state/get-auth-refresh-token)))