 (reg-event-db
   :auth-request
   (fn [app-state [_ signup?]]
-    (let [url       (if signup? "signup" "login")
-          ;; Should probalby centralize password validation, so we can use the same function
+    (let [url    (if signup? "signup" "login")
+          ;; Should probably centralize password validation, so we can use the same function
           ;; both here and when the UI is being updated
-          is-valid? (or (not signup?)
-                        (= (get-in app-state [:credentials :password])
-                           (get-in app-state [:credentials :password2])))]
-      (if is-valid?
+          valid? (or (not signup?)
+                     (= (get-in app-state [:credentials :password])
+                        (get-in app-state [:credentials :password2])))]
+      (if valid?
         (POST (str "/api/auth/" url) {:params        (:credentials app-state)
                                       :handler       #(dispatch [:auth-set-token (:token %)])
                                       :error-handler #(dispatch [:auth-request-error %])}))

(reg-event-db
  :state-ui-section
  (fn [app-state [_ section]]
    (if (= :remember section)
      (dispatch [:memories-load]))
    ; Do not associate nil sections

    (if (not-empty token)
      (dispatch [:state-message ""]))
    (cookies/set! :token token)
    (trace "Got token" token app-state)
    (trace "Current state" (bidi-matcher (-> js/window .-location .-pathname)))
    (cond
      (empty? token) (dispatch [:state-ui-section :login])
      (= :signup (get-in app-state [:ui-state :section])) (dispatch [:state-ui-section :record])
      :else (set-page! (bidi-matcher (-> js/window .-location .-pathname))))
    (-> app-state
        (assoc-in [:credentials :token] token)
        (assoc-in [:ui-state :wip-login?] false)
