title: How to distinguish an authenticated user at client side with Passport and node.js?
body: <p>I use <strong><code>Passport.js</code></strong> with <strong><code>MongoStore</code></strong> for authentication, I use <strong><code>express</code></strong> as web framework.  Once a user has logged in he can access to content at a certain route.</p>
  
  <p><strong>I'd like to offer distinct contents depending on which user has authenticated</strong>. Let's say at Mongo collection of <code>members</code> each got a <em><code>category</code></em> or <em><code>privileges</code></em> attribute and upon of it I'll condition what to display to him.</p>
  
  <p>I'll be using <strong><code>AngularJS</code></strong> for binding and rendering HTML.</p>
  
  <blockquote>
    <p>This is my routes managing:</p>
  </blockquote>
  
  <pre><code>app.get('/',function (request, response) {
  
      if(request.isAuthenticated()) 
          response.redirect('/admin')
      else
          response.sendfile("public/index.html")
  })
  
  
  app.get('/admin',function (request, response) {
  
      if(request.isAuthenticated()) 
          response.sendfile("views/admin.html") 
      else 
          response.redirect('/')
  })
  
  app.post('/login',
    passport.authenticate('local', {
      successRedirect: '/admin',
      failureRedirect: '/'
    })
  )
  
  app.get('/logout', function (request, response){
    request.session.destroy(function (err) {
      response.redirect('/'); //Inside a callback… bulletproof!
    })
  })
  
  app.get('*',function (request, response) {
  
      response.redirect('/')
  })
  </code></pre>
  
  <blockquote>
    <p>And this is my <strong><code>Passport.js</code></strong> code:</p>
  </blockquote>
  
  <pre><code>mongoose.connect('mongodb://localhost/integraDB')
  var Schema = mongoose.Schema
  var userCredential = new Schema({
  
      username:   String,
      password:   String
  
  },  {
      collection:     'members'
  })
  
  var userCredentials = mongoose.model('members', userCredential)
  
  
  
  app.use(session({
      clear_interval: 900,
      cookie: { maxAge: 2 * 60 * 60 * 1000 },
      store: new MongoStore({
        db : mongoose.connection.db
      })
    }));
  
  
  passport.serializeUser(function(user, done) {
    done(null, user);
  })
  
  passport.deserializeUser(function(user, done) {
    done(null, user);
  })
  
  passport.use(new LocalStrategy(function(username, password, done) {
    process.nextTick(function() {
      userCredentials.findOne({
        'username': username, 
      }, function(err, user) {
        if (err) {
          return done(err);
        }
  
        if (!user) {
          return done(null, false);
        }
  
        if (user.password != password) {
          return done(null, false);
        }
  
        return done(null, user);
      });
    });
  }))
  </code></pre>
  
  <p>How can I achieve this?</p>