Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to passing data in TwitterStrategy, PassportJS?
    primarykey
    data
    text
    <p>I have three kind of user:</p> <ol> <li><strong>Viewer</strong> (link to sign in: auth/<strong>v</strong>/twitter) </li> <li><strong>Creator</strong> (link to sign in: auth/<strong>c</strong>/twitter) </li> <li><strong>Admin</strong> (link to sign in: auth/<strong>a</strong>/twitter) </li> </ol> <p>And also I have 3 different db/collection </p> <ol> <li><strong>c_viewer</strong> </li> <li><strong>c_creator</strong> </li> <li><strong>c_admin</strong> </li> </ol> <p>Where each kind of user have a different link to sign in.</p> <p>Now let's take a look at the codes</p> <pre><code>var passport = require('passport') ,TwitterStrategy = require('passport-twitter').Strategy; passport.use(new TwitterStrategy({ consumerKey: config.development.tw.consumerKey, consumerSecret: config.development.tw.consumerSecret, callbackURL: config.development.tw.callbackURL }, function(token, tokenSecret, profile, done) { process.nextTick(function(req, res) { var query = User.findOne({ 'twId': profile.id}); query.exec(function(err, oldUser){ if(oldUser) { done(null, oldUser); } else { var newUser = new User(); newUser.twId = profile.id; newUser.twUsername = profile.username; newUser.name = profile.displayName; newUser.avatar = profile.photos[0].value; -&gt; newUser.age = req.body.creator.age; ??? newUser.save(function(err) { if(err) throw err; done(null, newUser); }); }; }); }); })); app.get('/auth/c/twitter', passport.authenticate('twitter'), function(req, res) { var userUrl = req.url; // codes to pass the userUrl to TwitterStrategy }); app.get('/auth/twitter/callback', passportForCreator.authenticate('twitter', { successRedirect: '/dashboard', failureRedirect: '/' })); </code></pre> <p>And this is my form</p> <pre><code>&lt;input type="text" name="creator[age]" placeholder="How old are you?"&gt; &lt;a id="si" class="btn" href="/auth/c/twitter"&gt;Sign in&lt;/a&gt; </code></pre> <h2><strong>My questions:</strong></h2> <p><strong>1.</strong> Can We pass <code>&lt;input&gt;</code> data to the login process? so We can read the input data in TwitterStrategy, and save to the db<br> <strong>2.</strong> Can We get "c" from login url (auth/ <strong>c</strong> /twitter) and pass it to TwitterStrategy? so we can simply check in different db/collection and change the query.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload