         (auth/set-in-progress! false)
         (auth/set-user!        nil)
         (auth/set-error!       "Authentication failed"))))
-
 
 (register-handler-for
   :auth-success

      (debug (str "Dispatch " event-name))
      (apply handler-fn (concat [db] (rest evt))))))

;; Generic handlers
;; -------------------------------------------------------------


    (auth/set-user! db nil)))

(register-handler-for
 :login
 (fn [db user-pwd]
   (let [sign-in api/signin]
     (sign-in :user {:username (:user user-pwd) :password (:pwd user-pwd)}
              :on-success (fn [user-res] (dispatch [:auth-success (:data user-res)]))
              :on-error
              #(condp = (:type %)
                 :invalid-credentials (dispatch [:auth-fail])
                 :network-error (dispatch [:set-offline true])
                 (dispatch [:unknown-error])))

     (-> db
         (auth/set-in-progress! true)
         (auth/set-user!        nil)
         (auth/set-error!       nil)))))

(register-api-call-handler
 :begin-api-event-key  :auth/login
 :api-call             api/signin
 :init-fn              (fn [db user]
                         (-> db
                             (auth/set-user!  nil)
                             (auth/set-error! nil)))
 :params-fn            (fn [db user-pwd]
                         {:user {:username (:user user-pwd) :password (:pwd user-pwd)}})
 :success-fn           (fn [db user]
                         (when (= (:page db) "login")
                           (dispatch [:set-page :inbox]))
                         (-> db
                             (auth/set-user! user)))
 :error-fn             (fn [db]
                         (-> db
                             (auth/set-error! "Authentication failed")))
 )

(register-handler-for
  :auth-fail
