var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();

// Passport configurators..
var loopbackPassport = require('loopback-component-passport');
var PassportConfigurator = loopbackPassport.PassportConfigurator;
var passportConfigurator = new PassportConfigurator(app);

// attempt to build the providers/passport config
var config = {};
try {
	config = require('../providers.json');
} catch (err) {
	console.trace(err);
	process.exit(1); // fatal
}

// Set up the /favicon.ico
app.use(loopback.favicon());

// request pre-processing middleware
app.use(loopback.compress());

// -- Add your pre-processing middleware here --
app.use(loopback.token({
	model: app.models.accessToken
}));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

// boot scripts mount components like REST API
boot(app, __dirname);

app.use(loopback.cookieParser(app.get('cookieSecret')));
app.use(loopback.session({
	secret: 'kitty',
	saveUninitialized: true,
	resave: true
}));
passportConfigurator.init();

passportConfigurator.setupModels({
	userModel: app.models.user,
	userIdentityModel: app.models.userIdentity,
	userCredentialModel: app.models.userCredential
});
for (var s in config) {
	var c = config[s];
	c.session = c.session !== false;
	passportConfigurator.configureProvider(s, c);
}
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;

app.get('/', function(req, res, next) {
  res.render('index', {user: req.user});
});

app.get('/auth/account', ensureLoggedIn('/login.html'), function(req, res, next) {
  res.render('loginProfiles', {user: req.user});
});

app.get('/link/account', ensureLoggedIn('/login.html'), function(req, res, next) {
  res.render('linkedAccounts', {user: req.user});
});

app.get('/auth/logout', function(req, res, next) {
  req.logout();
  res.redirect('/');
});

// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
var path = require('path');
app.use(loopback.static(path.resolve(__dirname, '../client/public')));

// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());

// The ultimate error handler.
app.use(loopback.errorHandler());

app.start = function() {
	// start the web server
	return app.listen(function() {
		app.emit('started');
		console.log('Web server listening at: %s', app.get('url'));
	});
};

// start the server if `$ node server.js`
if (require.main === module) {
	app.start();
}

@@ -680,69 +680,8 @@
  --%0A
-app.use(loopback.token(%7B%0A%09model: app.models.accessToken%0A%7D));%0A
 app.
@@ -814,24 +814,136 @@
 _dirname);%0A%0A
+// The access token is only available after boot%0Aapp.use(loopback.token(%7B%0A  model: app.models.accessToken%0A%7D));%0A%0A
 app.use(loop

Fix the token middleware