Created
April 13, 2014 13:57
-
-
Save jeffdonthemic/10585295 to your computer and use it in GitHub Desktop.
Setting nforce org in express session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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