So I have followed this tutorial . I finished the whole series and the application is working fine. However I would like for users who signup using a social network eg. Facebook etc. to be redirected to a seperate form where they can fill their name(s) email etc. Couple of questions.
Would I have to change the database schema to allow 'global'(is this the correct term to use?) values for email and name etc. from the facebook/twitter specific stuff. Like so:
var userSchema = mongoose.Schema({ email : String, name : String password : String, facebook : { id : String, token : String, }, twitter : { id : String, token : String, displayName : String, username : String, }, google : { id : String, token : String, } });
What then would be the correct route? I currently have:
// TWITTER ROUTES
// route for facebook authentication and login
app.get('/auth/twitter', passport.authenticate('twitter'));
// handle the callback after twitter has authenticated the user
app.get('/auth/twitter/callback',
passport.authenticate('twitter', { failureRedirect: '/signup' }),
function(req, res) {
// The user has authenticated with Twitter. Now check to see if the profile
// is "complete". If not, send them down a flow to fill out more details.
if (req.user.isCompleteProfile()) {
res.redirect('/profile');
} else {
res.redirect('/complete-profile');
}});
app.get('/complete-profile', function(req, res) {
res.render('profile-form', { user: req.user });
});
app.post('/update-profile', function(req, res) {
// Grab the missing info from the form and update the profile.
res.redirect('/home');
});
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated ())
return next();
// if they arent redirect them to the home page
res.redirect('/');
}
I took it from this StackOverflow .
How would I define the function isCompleteProfile
? Currently I have something like this:
function isCompleteProfile(req, res, next) {
// if user has completed profile, carry on
if (req.isComplete ())
return next();
// if they arent redirect to complete-profile
res.redirect('/complete-profile');
}
The first link (to the tutorial) has some suggestions by the author on how to implement this, in the comment section below the article if anyone needs it. However I have mainly been looking at the SO link.
Obviously it is not working (I just copied the earlier function for isLoggedIn
. Creating views should (hopefully) not be too difficult. So if anyone can shed some light on how I should solve this issue it will be greatly appreciated.
Thanks Uknj
PostScript: Is there also potentially an alternative method? Where I do not use a separate function in the route and just redirect them to another page directly? Not sure how I would do this either, so help would be appreciated.
请参阅我关于使用Everyauth / Passport.js通过Twitter进行身份验证的说明,同时询问用户名/电子邮件/密码 ,以获取有关如何设置isCompleteProfile测试的说明。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.