Browse Source

fix: refresh tokens when starting the app

Tienson Qin 2 years ago
parent
commit
a46b7226ad

+ 13 - 14
src/main/frontend/components/file_sync.cljs

@@ -409,7 +409,6 @@
                  (str "status-of-" (and (keyword? status) (name status)))])}
        (when (and (not config/publishing?)
                   (user-handler/logged-in?))
-
          (ui/dropdown-with-links
           ;; trigger
           (fn [{:keys [toggle-fn]}]
@@ -428,21 +427,21 @@
                (ui/icon "cloud-off" {:size ui/icon-size})]))
 
           ;; links
-          (cond-> []
+          (cond-> (vec
+                   (when-not (and no-active-files? idle?)
+                     (cond
+                       need-password?
+                       [{:title   [:div.file-item.flex.items-center.leading-none.pt-3
+                                   {:style {:margin-left -8}}
+                                   (ui/icon "lock" {:size 20}) [:span.pl-1.font-semibold "Password is required"]]
+                         :options {:on-click fs-sync/sync-need-password!}}]
+
+                       ;; head of upcoming sync
+                       (not no-active-files?)
+                       [{:title   [:div.file-item.is-first ""]
+                         :options {:class "is-first-placeholder"}}])))
             synced-file-graph?
             (concat
-             (when-not (and no-active-files? idle?)
-               (cond
-                 need-password?
-                 [{:title   [:div.file-item.flex.items-center.leading-none.pt-3
-                             (ui/icon "lock" {:size 20}) [:span.pl-1.font-semibold "Password is required"]]
-                   :options {:on-click fs-sync/sync-need-password!}}]
-
-                 ;; head of upcoming sync
-                 (not no-active-files?)
-                 [{:title   [:div.file-item.is-first ""]
-                   :options {:class "is-first-placeholder"}}]))
-
              (map (fn [f] {:title [:div.file-item
                                    {:key (str "downloading-" f)}
                                    (gp-util/safe-decode-uri-component f)]

+ 0 - 4
src/main/frontend/components/file_sync.css

@@ -159,10 +159,6 @@
       .title-wrap {
         flex: 1;
       }
-
-      .menu-link {
-        @apply px-2;
-      }
     }
 
     &.is-enabled-progress-pane {

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

@@ -133,24 +133,15 @@
           (set-tokens! (:id_token (:body resp)) (:access_token (:body resp)))))))))
 
 (defn restore-tokens-from-localstorage
-  "Restore id-token, access-token, refresh-token from localstorage,
-  and refresh id-token&access-token if necessary.
-  return nil when tokens are not available."
+  "Refresh id-token&access-token, pull latest repos, returns nil when tokens are not available."
   []
   (println "restore-tokens-from-localstorage")
-  (let [id-token (js/localStorage.getItem "id-token")
-        access-token (js/localStorage.getItem "access-token")
-        refresh-token (js/localStorage.getItem "refresh-token")]
+  (let [refresh-token (js/localStorage.getItem "refresh-token")]
     (when refresh-token
-      (set-tokens! id-token access-token refresh-token)
-      (when (or (nil? id-token) (nil? access-token)
-                (-> id-token parse-jwt almost-expired?)
-                (-> access-token parse-jwt almost-expired?))
-        (go
-          ;; id-token or access-token expired
-          (<! (<refresh-id-token&access-token))
-          ;; refresh remote graph list by pub login event
-          (when (user-uuid) (state/pub-event! [:user/login])))))))
+      (go
+        (<! (<refresh-id-token&access-token))
+        ;; refresh remote graph list by pub login event
+        (when (user-uuid) (state/pub-event! [:user/login]))))))
 
 (defn login-callback [code]
   (state/set-state! [:ui/loading? :login] true)