                   (do
                    (>! out {:topic ::auth-required :users (set (map :user not-auth)) :tries-left (- 5 counter)})
                    (<! (go-loop [p (<! pub-ch)]
-                         (if (= (:topic p) ::authed)
-                           (swap! sessions (fn [old new] (apply assoc old new)) (:users p))
+                         (if (= (:topic p) ::auth)
+                           (swap! sessions (fn [old new] (apply assoc old new))
+                                  (->> (:users p)
+                                       (map
+                                        (fn [[k v]]
+                                          (vec [k
+                                                (if (credential-fn {:username k :password v})
+                                                  (-> {(uuid) (java.util.Date.)})
+                                                  nil)])))
+                                       flatten))
                            (recur (<! pub-ch)))))
-                   (recur (inc counter))))
-                 ))))))
+                   (recur (inc counter))))))))))
     (recur (<! pub-ch))))
 
 
-(defn- auth-required [auth-req-ch auth-fn out]
+(defn- auth-required
+  "Sends the credntials of given users back using a given authentication function"
+  [auth-req-ch auth-fn out]
   (go-loop [{:keys [users] :as a} (<! auth-req-ch)]
     (when a
       (debug "AUTH-REQ" users)

      (println "OUT" (<! out))
      ))


  (println "\n")


  )

      (recur (<! auth-req-ch)))))


(defn- in-dispatch
  "Dispatches incoming requests"
  [{:keys [topic]}]
  (case topic
    :meta-pub :meta-pub
    ::auth-required ::auth-required
    ::auth :meta-pub
    :unrelated))


