'How do I fix authentication not working when I send a request from react frontend but that works in backend?

So I have this app that interacts with an api on localhost, I'm using express, mongodb and react for the frontend. passport local auth for authentication. I have a problem where authentication doesn't persist when I use the fetch api in react. When I use postman to make the post request everything is alright and my auth status returns true. Pretty sure passport initialization is in order because in postman it works just fine. The confusing thing is that I use the same body for both. POST request in express:

router.post('/login', user_controller.user_login_post, (req, res) => {
  console.log(req.body);
  if (!req.user) {
    console.log('User not found!');
    res.send(req.body);
  } else {
    console.log('Signed in');
    res.send(req.body);
  }
});

login_post in controller:

exports.user_login_post = passport.authenticate('local');
```

Auth checking in express/passport:
```
app.get('/api/checkauthentication', (req, res) => {
  req.isAuthenticated()
    ? res.status(200).json({ authenticated: true })
    : res.status(401).json({ authenticated: false });
});
```
Function I'm calling on submit in React:
```
  const login = (data) => {
    fetch('/api/users/login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
      credentials: 'include',
    })
      .then((response) => response.json())
      .then((data) => console.log('DATA: ', data))
      .catch((err) => {
        console.log('Error: ', err);
      });
  };
```

Also 'Signed in' gets logged out but auth only persists when I make the request from postman.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source