title: How to access result from the previous promise in AngularJS promise chain?
body: <p>I have the following code:</p>
  
  <pre><code>authService.authenticate()
  .then(function (user) {
    return Task.all({user: user})
  })
  .then(function (tasks) {
    // How to access user object here?
  })
  </code></pre>
  
  <p>Is there some built-in way to pass <code>user</code> object to the second <code>then</code> function without doing something like this:</p>
  
  <pre><code>var user2 = null;
  authService.authenticate()
  .then(function (user) {
    user2 = user
    return Task.all({user: user})
  })
  .then(function (tasks) {
     // Use user2 here
  })
  </code></pre>
  
  <p>or this:</p>
  
  <pre><code>authService.authenticate()
  .then(function (user) {
    var defer = $q.defer()
    Task.all({user: user}).then(function (tasks) {
      return defer.resolve(user, tasks)
    })
    return defer.promise
  })
  .then(function (user, tasks) {
     // Use user2 here
  })
  </code></pre>
  
  <p>or nesting them by calling the second <code>then</code> directly on <code>Task.all</code> (this way I'd have <code>user</code> object available via closure)? 
  Nesting them is exactly what I'm trying to avoid.</p>