generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

questions: page redirect after successful social (i.e. facebook) login

Open footloosemoose opened this issue 12 years ago • 4 comments

Hi everyone (my first post here - thanks to all for the excellent work)

I'm having trouble redirecting to a dashboard page ('/me') after a successful facebook login.

I have tried setting the 'successRedirect' option in the passport.authenticate method with no luck.

// not working for me...
.get('/', passport.authenticate('facebook', {
    successRedirect: '/me',
    failureRedirect: '/signup',
    session: false
  }))

I have also tried updating the authCallback function in user.controller.js with

// not working for me...
exports.authCallback = function(req, res, next) {
  res.redirect('/me');
};

All attempts so far just dump me out back at '/'.

I'm wondering if it has something to do with the catch-all in the routes?

// All other routes should redirect to the index.html
  app.route('/*')
    .get(function(req, res) {
      res.sendfile(app.get('appPath') + '/index.html');
    });

No doubt this is something I'm overlooking. Any help would be very much appreciated.

footloosemoose avatar Jul 17 '14 05:07 footloosemoose

The catch all route redirects to the index.html for all undefined server routes so that the angularJS routing system can kick in.

If you want the me route to be part of your angularJS app, you'll probably want to generate it using yo angular-fullstack:route me

Otherwise, if its a route thats going to be handled by server side rendering, then you'll have to define it in your express routes before the catch all.

DaftMonk avatar Jul 17 '14 05:07 DaftMonk

Thanks @DaftMonk

I must be doing something else wrong as I do have the route defined and working in Angular.

I can cut and paste http://localhost:9000/me into the browser and it works as expected. It's just the callback from the social auth side of things that isn't behaving.

If nothing springs to mind it could very easily be a mistake I've made elsewhere. I'll keep looking! Thanks again.

Update: If anyone manages to get a social login redirecting to a non-root page, can you please let me know?

footloosemoose avatar Jul 17 '14 07:07 footloosemoose

@footloosemoose Had the same challenge. try updating the setTokenCookie in auth.service.js by adding res.redirect('/me'). should look similar to: function setTokenCookie(req, res) { if (!req.user) return res.json(404, { message: 'Something went wrong, please try again.'}); var token = signToken(req.user._id, req.user.role); res.cookie('token', JSON.stringify(token)); res.redirect('/me'); }

martinbutler avatar Nov 25 '14 23:11 martinbutler

@martinbutler, know how to do this for local login as well?

dcoffey3296 avatar Apr 20 '15 20:04 dcoffey3296