4

I am using the angular-fullstack (https://github.com/DaftMonk/generator-angular-fullstack) from the yeoman generator for the MEAN stack. I am new to most of these technologies and am just beginning to wrap my head around how the pieces fit together.

I am trying to figure out how to redirect a freshly authenticated user to the URL that they originally requested before they logged in.

In

myproject/server/auth/auth.service.js

there is this function which appears to redirect back to '/' after an oAuth login:

/**
 * Set token cookie directly for oAuth strategies
 */
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('/');
}

How would I go about remembering the original request for both oAuth AND local login and then were would I redirect the user appropriately after they log in? Thanks!!

dcoffey3296
  • 2,504
  • 3
  • 24
  • 34

1 Answers1

3

I figured this out, finally! I had to make changes in 3 files. I made a gist to highlight the changes:

https://gist.github.com/dcoffey3296/d27c141ef79bec3ff6a6

dcoffey3296
  • 2,504
  • 3
  • 24
  • 34
  • Thank you so much! After spending about 2 hours trying to figure this out, your code worked perfectly! – Jayson H May 01 '16 at 06:59