title: cannot understand what callback does in a Connect module
body: <p>I am reading a book about NodeJs Connect. There is this small part about <code>basicAuth</code> module. I know that <code>basicAuth</code> is now deprecated, but I cannot understand this simple code. The book says </p>
  
  <blockquote>
    <p>Providing an asynchronous callback function</p>
    
    <p>The final option is similar, except this time a callback is passed to
    basicAuth() with three arguments defined, which enables the use of
    asynchronous lookups. This is useful when authenticating from a file
    on disk, or when querying from a database.</p>
    
    <p>Listing 7.7. A Connect basicAuth middleware component doing
    asynchronous lookups</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/GKdvr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GKdvr.png" alt="enter image description here"></a></p>
  
  <p>And no other information. Thats the whole part about having a callback in the <code>basicAuth</code></p>
  
  <p>So, code gets the username and the password. Then hypothetical object <code>User</code> has a method <code>authendicate</code> that checks if this user actually exists. And when its finished, calls the <code>gotUser</code> function. <code>gotUser</code> contains either a returned error (=no user found with that username/password) or a returned user object (a user found with that username/password). Am I right?</p>
  
  <p><code>gotUser</code> checks if there is an error. If there is, returns and calls <code>callback</code> with an error argument. So wait, what will <code>callback</code> do at this point? Its not defined anywhere. Will it pass the error to an error handler function? And how?</p>
  
  <p>If there is not an error, <code>gotUser</code> calls <code>callback</code> again with <code>null</code>(= no error) and <code>user</code>. Once again, what will callback do? Why pass the returned user to the callback and not grab its name, mail, age etc etc and use them on a session or fill the <code>innerHTML</code> of a tag or whatever?</p>
  
  <p>Thanks</p>