Skip to content

Instantly share code, notes, and snippets.

@jeffdonthemic
Created April 13, 2014 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffdonthemic/10585295 to your computer and use it in GitHub Desktop.
Save jeffdonthemic/10585295 to your computer and use it in GitHub Desktop.
Setting nforce org in express session
var nforce = require('nforce');
/**
* Salesforce configuration.
*/
var org = nforce.createConnection({
clientId: process.env.SFDC_CLIENT_ID,
clientSecret: process.env.SFDC_CLIENT_SECRET,
redirectUri: 'http://localhost:3000/oauth/_callback',
environment: 'production', // optional, salesforce 'sandbox' or 'production', production default
mode: 'single' // optional, 'single' or 'multi' user mode, multi default
});
org.authenticate({ username: process.env.SFDC_USERNAME, password: process.env.SFDC_PASSWORD}, function(err, resp){
// the oauth object was stored in the connection object
if(err) console.error('✗ Could not connect to Saleforce org.');
if (!err) console.log('sucessfully connected');
});
/**
* Express configuration.
*/
app.use(function(req, res, next) {
res.locals.org = org;
res.locals.user = req.user;
res.locals.token = req.csrfToken();
res.locals.secrets = secrets;
next();
});
exports.show = function(req, res) {
Group.findOne({'_id': req.params.id}, function(err, item) {
res.locals.org.query({ query: item.query }, function(err, resp){
if(!err && resp.records) {
console.log(resp.records);
res.render('groups/show', {
title: 'Group details', record: item, records: resp.records
});
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment