angularjs - Login via passport facebook strategy with angular ui router -


i have implemented client side routing using 'angular ui router'. using passport facebook strategy @ server side handle facebook based authenticatoin.

i have angular routes follows:

angular.module('homepage'). config(function($stateprovider, $urlrouterprovider) {      $urlrouterprovider.otherwise('/');      $stateprovider          // index states  ========================================         .state('index', {             url: '/',             templateurl: '../../html/partials/partial-index.html'         })          // home page , multiple named views =================================         .state('home', {             url: '/home',             templateurl: '../../html/partials/partial-home.html'         });  }); 

now initiate authentication on click following link:

<a class="clickable" href="/auth/facebook">log in</a> 

following server side routes:

// route facebook authentication , login app.get('/auth/facebook',     passport.authenticate('facebook', {         scope : 'email'     }));  // handle callback after facebook has authenticated user app.get('/auth/facebook/callback',     passport.authenticate('facebook', {         successredirect : '/success',         failureredirect : '/login'     }));  app.get('/success', isloggedin, function(req, res) {     // client side redirection without passing user info     res.redirect('/#/home'); }); 

on authentication success, page reloads , loads 'localhost:8888/#/home' , loads 'home' route state. but issue have not recieved user info @ client side after redirection happened.

ideally follows:

app.get('/success', isloggedin, function(req, res) {     // ideally     res.json({         path: '/#/home',         user : req.user // user out of session , pass template     }); }); 

but dont know how pass info angularjs current page context nodejs routes. how can implement this.

what approach authenticate via facebook strategy , angular route redirection while passing user info angular.

you should write custom response handler passport when use strategy. this:

passport.use(new facebookstrategy({     clientid: facebook_app_id,     clientsecret: facebook_app_secret,     callbackurl: "http://localhost:3000/auth/facebook/callback"   },   function(accesstoken, refreshtoken, profile, cb) {     user.findorcreate({ facebookid: profile.id }, function (err, user) {       return cb(err, user);     });   } )); 

are wrote that?

don't forget user serialization:

// used serialize user session passport.serializeuser(function(user, done) {     done(null, user.id); });  // used deserialize user passport.deserializeuser(function(id, done) {     user.findbyid(id, function(err, user) {         done(err, user);     }); }); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -