bnoguchi/everyauth — Issue #167: no req.user inside page callbacks.
Author: bbayer
Created: 2012-01-31 22:27:20+00:00
State: open

Hello,
I am using express and everyauth. You can find attached code example below. The problem is everyauth.user is working as expected inside jade views but req.user doesn't work inside page callbacks. The strange part is req.loggedIn is provided by middleware but req.user not.

```javascript
/**
* Module dependencies.
*/

var express = require('express')
, routes = require('./routes')
, everyauth = require('everyauth')
, Promise = everyauth.Promise
, util = require('util')
, models = require('./models');

//Everyauth setup

everyauth.twitter
.consumerKey('XXX')
.consumerSecret('XXX')
.findOrCreateUser(function(session, accessToken, accessTokenSecret, twitterData){
var promise = new Promise();
models.findOrCreateTwitterUser(twitterData,promise);
return promise;
})
.redirectPath('/');

var app = module.exports = express.createServer();
// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser());
app.use(express.session({secret:"Iam james bond"}));
app.use(express.methodOverride());
//app.use(app.router);
app.use(everyauth.middleware());
});

app.configure('development', function(){
everyauth.debug = true;
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', function(req, res){
if(req.loggedIn){
console.log(req.user); //<--This is always undefined
}
console.log("index");
res.render('index', { title: 'Welcome to Chat app' });
});

//Helpers
everyauth.helpExpress(app);

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
```