node.js Allow access only for logged in users

The reference to isLoggedIn in the route is an connect route middleware. Control is passed to the middleware function before the route function is called. Use isLoggedIn to verify that we have a user token in the session before we send the client the requested route.
If we do not have a user token in the session, then we redirect the client to the ‘/login’ route. This effectively locks down our routes from unauthenticated access.

function isLoggedIn(req, res, next) {
    if(req.session['FedTokenCookie']){
      next();
    }else{
      res.writeHead(301, {"Location":'/login'});
      res.end();
    }
};
app.get('/mails', isLoggedIn, function(req, res, next){
  ...;
});
app.get('/docs', isLoggedIn, function(req, res, next){
  ...;
});

9 thoughts on “node.js Allow access only for logged in users

  1. Hi there would you mind stating which blog platform you’re using?
    I’m planning to start my own blog in the near future but I’m having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking
    for something completely unique. P.S My apologies for being off-topic but
    I had to ask!

  2. It’s perfect time to make some plans for the future and it is time to be happy.

    I’ve read this post and if I may just I wish to counsel you some attention-grabbing issues or tips.
    Perhaps you can write subsequent articles relating to this article.
    I wish to read even more things approximately it!

  3. Their bodies are forged by compound work outs,
    mostly The Squat, Bench Press and Military Press. it is widely known that the secret of
    French women in losing weight is to eat things slowly.
    Research says that it could be a magic ingredient that lets you lose weight without dieting
    and exercise.

  4. My developer is trying to convince me to move to
    .net from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using
    WordPress on a variety of websites for about a year and am worried about switching to another platform.
    I have heard good things about blogengine.net.

    Is there a way I can import all my wordpress posts into it?
    Any kind of help would be greatly appreciated!

  5. Greetings from Los angeles! I’m bored at work so I decided to browse your blog on my iphone during
    lunch break. I enjoy the knowledge you provide here and can’t
    wait to take a look when I get home. I’m amazed at how fast your blog
    loaded on my cell phone .. I’m not even using WIFI, just 3G
    .. Anyhow, fantastic blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s