L
L
lemial2017-06-21 10:12:35
JSON
lemial, 2017-06-21 10:12:35

How to make a redirect after authorization in NODE?

Greetings, dear, tell me how to redirect to a specific page after successful authorization, having this code:

app.post("/login", function(req, res, next) {
   return login(req, res, next);
});

return login = function(req, res, next) {
  return passport.authenticate("local", function(err, user, info) {
    if (err) {
      return JsonRenderer.error(err, res, 401);
    }
    if (!user) {
      return JsonRenderer.error("Invalid credentials", res, 401);
    }
    return req.logIn(user, function(err) {
      if (err) {
        return JsonRenderer.error("Invalid credentials", res, 401);
      }
      return UserToken.findByUserAndType(user.id, "google_auth", function(err, googleToken) {
        if (googleToken && !googleToken.isValidGAuthPass(req.body.gauth_pass)) {
          req.logout();
          return JsonRenderer.error("Invalid Google Authenticator code", res, 401);
        }
          res.json(JsonRenderer.user(req.user));
            return AuthStats.log({
               ip: req.ip,
               user: req.user
            }, req.user.email_auth_enabled && !req.user.recenltySignedUp());
       });
    });
  })(req, res, next);
};

Do not judge strictly, just learn the basics of NODE.JS :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2017-06-21
@EreminD

well, where in your code (did not find) successful authorization, do a redirect
res.redirect(301, 'http://example.com');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question