integrating authentication to my app using Auth0 and node.js
<p>i'm developing application on cloud9 enviroment. using:</p>

<ul>
<li>node 4.43</li>
<li>express 4.13.4</li>
</ul>

<p>i have integrated my Demo Auth0 account into my on-dev application.
i am able to login (being redirected to the first page of my app), but when i'm printing req.isAuthenticated() i'm getting false. also req.user is undefined.</p>

<p>i have followed the <a href="https://auth0.com/docs/quickstart/webapp/nodejs#1-add-passport-dependencies" rel="nofollow">quick start</a> of auth0 for node.js.</p>

<p>i'm attaching the three files that are mainly invovled:</p>

<p>app.js:</p>

<pre><code>var express = require('express'),
    app = express(),
    BodyParser = require("body-parser"),
    mongoose = require("mongoose"),
    student = require ("./models/student"),
    students_class = require("./models/class"),
    // =============
    //     auth0
    // =============
    passport = require('passport'),
    strategy = require('./models/setup-passport'),
    cookieParser = require('cookie-parser'),
    session = require('express-session');
    app.use(cookieParser());
    app.use(session({ secret: 'FpvAOOuCcSBLL3AlGxwpNh5x-U46YCRoyBKWJhTPnee2UELMd_gjdbKcbhpIHZoA', resave: false,  saveUninitialized: false }));
    app.use(passport.initialize());
    app.use(passport.session());

    app.get('/login',passport.authenticate('auth0', { failureRedirect: '/url-if-something-fails' }),
  function(req, res) {

    res.send(req.user);
    if (!req.user) {
      throw new Error('user null');
    }
    res.redirect("/", {username: req.user});
  });





mongoose.connect("mongodb://localhost/myapp");

// ============================
//         routes
// ============================

var classRoutes = require("./routes/class"),
    indexRoutes = require("./routes/index"),
    studentRoutes = require("./routes/student"),
    assocRroutes = require ("./routes/assoc");

// ============================================
//         configuring the app
// ============================================
app.set("view engine", "ejs");
app.use(express.static ("public"));
app.use(BodyParser.urlencoded({extended: true}));
app.use(classRoutes);
app.use (indexRoutes);
app.use(studentRoutes);
app.use(assocRroutes);





app.listen(process.env.PORT, process.env.IP, function() {
    console.log('Attendance Server is Running ....');
});
</code></pre>

<p>setup-passport.js</p>

<pre><code>var passport = require('passport');
var Auth0Strategy = require('passport-auth0');

var strategy = new Auth0Strategy({
    domain:       'me.auth0.com',
    clientID:     'my-client-id',
    clientSecret: 'FpvAOOuCcSBLL3AlGxwpNh5x-U46YCRoyBKWJhTPnee2UELMd_gjdbKcbhpIHZoA',
    callbackURL:  '/callback'
  }, function(accessToken, refreshToken, extraParams, profile, done) {
    // accessToken is the token to call Auth0 API (not needed in the most cases)
    // extraParams.id_token has the JSON Web Token
    // profile has all the information from the user
    return done(null, profile);
  });

passport.use(strategy);

// This is not a best practice, but we want to keep things simple for now
passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

module.exports = strategy;
</code></pre>

<p>index.js (the actual fisrt page where i want to re-direct after successful login:</p>

<pre><code>var express = require("express");
var passport = require('passport');
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn();
var router = express.Router();
var student = require ("../models/student");

//INDEX 

router.get("/callback", function(req, res) {
    student.find({}, function(err, student) {
        console.log(req.isAuthenticated())
        if (err) {
            console.log(err);
        } else {
            res.render("home/index.ejs", {
                students: student
            });
        }

    });
});


module.exports = router;
</code></pre>

<p>any suggestion what could go wrong?
also wierd for me that on app.js, the guide is initializing the variable strategy but actually never seem to use it.</p>

<p>BUMP</p>