I'm trying to set up goals in Google Analytics to track Sign Ups, so I created a thank you page as my goal URL. It works well when my users register with their email address, but not when they use facebook to register / login. When they log in, they are redirected to the thank you page, because when setting up Facebook using Passport JS and Node, there is only one URL callback.
Here is my code:
passport.serializeUser(function(user, done) { done(null, user); }); passport.deserializeUser(function(id, done) { UserActivity.findOne(id,'uid ref', function (err, user) { done(err, user); }); }); passport.use(new FacebookStrategy({ clientID: 'XXXXXXXXXXXX', clientSecret: 'XXXXXXXXXXXXXXXX', callbackURL: "https://www.xxxxxxx.com/auth/facebook/callback" }, function(accessToken, refreshToken, profile, done) { //console.log(profile); User.findOne({ uid: profile.id }, function(err, uInfo) { if(err) console.log('Error: '+err); else{ //User exists: we are done if(uInfo){ done(err, uInfo); } else{ //User doesn't exist: we create a new one var newUser = new User ({ uid: profile.id, email:profile.emails[0].value, ref: 'Facebook' }); // Saving it to the database. newUser.save(function (err,uInfo) { if (err) console.log ('Error on save!'); done(err, uInfo); }); } } }) } )); app.get('/auth/facebook', passport.authenticate('facebook',{ scope: 'email' })); app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/thankyou', failureRedirect: '/login' }));
If the user exists, I would like to redirect him to the control panel ('/ dashboard), and if they are new users, I need to redirect them to / thankyou. Any idea how to achieve this?
Thanks a lot!