0

enter image description here enter image description here** hi every i have problem i cant redirect to my react app its redirect to html instend react route its shows error in inspect window network XHR :

cant get /login 
, and the response headers : Content-Type: text/html; charset=UTF-8 , and status code : 304 Not Modified but when i click the request on inspect i get the react route / or /account/login what i have to do *

app.post('/login', function(req, res, next) {
  passport.authenticate('local', function(err, user, info) {
    if (err) { return next(err); }
    if (!user) { return res.redirect('/login'); }
    req.logIn(user, function(err) {
      if (err) { return next(err); }
      return res.redirect('/');
    });
  })(req, res, next);
});

app.get('/login',(req, res) => {
  if (req.user) {
    res.redirect ('/');
  }
  res.redirect ('/account/login');
};
9
  • can you clarify more on what you are trying to acheive Commented May 27, 2020 at 22:16
  • ok just min to fix Commented May 27, 2020 at 22:18
  • just left an answer so let me know if it helps Commented May 27, 2020 at 22:25
  • can you please see the seconde pic i mean it shouldnot show html responce must redirect to react router Commented May 27, 2020 at 22:25
  • in the second pic if i clicked to localhost i nav to home route (react app) but i need if any one click signin and successfull signin must navigate to route('/') Commented May 27, 2020 at 22:32

1 Answer 1

1

When using res.redirect() it redirects to the current domain it's on So Instead what you want do is

  const PROJECT_DOMAIN = 'https://myapp.com'; suppose your app is in production
 res.redirect(`${PROJECT_DOMAIN }/account/login`)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.