Book Image

Learning Single-page Web Application Development

Book Image

Learning Single-page Web Application Development

Overview of this book

Table of Contents (15 chapters)
Learning Single-page Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Dealing with routes


Now that we have completed the implementation of user authentication, we need to configure the application routes to handle the validation and creation of users.

Let's make some changes in the index.js file inside the routes folder:

  1. Add the following highlighted code to the index.js file:

    var express = require('express');
    var router = express.Router();
    var passport = require('passport');
    
    /* GET home page. */
    router.get('/', function(req, res) {
      res.render('index.ejs');
    });
    
    module.exports = router;

    Note that we set up the default router to render a page called index.ejs. We have not created this page yet, but we will do so soon; for now, we will continue setting the necessary routes to handle authentication.

  2. Let's create the route for a profile.ejs page; place the following code after the home page route function:

    /* GET profile page. */
    router.get('/profile', isLoggedIn, function(req, res) {
      res.render('profile.ejs', {
        user : req.user
      });
    });

    Here, we passed an isLoggedIn...