noa
noa

Reputation: 1

error redirect to react after local auth with passport using node js express

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');
};

Upvotes: 0

Views: 206

Answers (1)

Adebayo Ilerioluwa
Adebayo Ilerioluwa

Reputation: 339

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`)

Upvotes: 1

Related Questions