title: Google login with PassportStrategy in NestJS backend not working called by React WebApp
body: <p>I've implemented Google login with PassportStrategy in NestJS backend (NestJS backend development is based on this guide: <a href="https://medium.com/@nielsmeima/auth-in-nest-js-and-angular-463525b6e071" rel="nofollow noreferrer">https://medium.com/@nielsmeima/auth-in-nest-js-and-angular-463525b6e071</a>).</p>
  <pre><code>@Get('google')
  @UseGuards(AuthGuard('google'))
  googleLogin()
  {
      // initiates the Google OAuth2 login flow
  }
  
  @Get('google/callback')
  @UseGuards(AuthGuard('google'))
  googleLoginCallback(@Req() req, @Res() res)
  {
      // handles the Google OAuth2 callback
      const jwt: string = req.user.jwt;
      if (jwt)
          return res.status(HttpStatus.OK).cookie('jwt', jwt, {
              httpOnly: true
          }).redirect('/');
      else 
          res.redirect('http://localhost:4200/login/failure');
  }
  </code></pre>
  <p>With @UseGuards(AuthGuard('google')) should start the google login:</p>
  <pre><code>super({
          clientID    : 'XXX',     // &lt;- Replace this with your client id
          clientSecret: 'XXX', // &lt;- Replace this with your client secret
          callbackURL : 'http://myapp.herokuapp.com/auth/google/callback',
          passReqToCallback: true,
          scope: ['profile']
      })
  </code></pre>
  <p>If I put the call auth/google in the address bar of a browser it works.</p>
  <p>If I call the method auth/google from a React WebApp it doesn't work and the network requests are those in the screenshot. I've no data in response.</p>
  <p><a href="https://i.stack.imgur.com/XCVnb.jpg" rel="nofollow noreferrer">App Requests</a></p>
  <p><a href="https://i.stack.imgur.com/dmK0a.jpg" rel="nofollow noreferrer">Google Detail</a></p>
  <p>It seems that the callback doesn't start, but &quot;passReqToCallback: true&quot; works.</p>
  <p>React frontend request:</p>
  <pre><code>fetch(&quot;http://&lt;url&gt;/auth/google&quot;, {
    method: &quot;GET&quot;,
    mode: 'no-cors',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    }
  })
  .then(
    (result) =&gt; {
          if (result) {
            history.push({
              pathname: '/home'
            });
          }
    },
    (error) =&gt; {
      
    }
  );
  </code></pre>
  <p>Backend logs when login goes well:</p>
  <blockquote>
  <p>2021-02-18T10:34:02.724706+00:00 heroku[router]: at=info method=GET path=&quot;/auth/google/&quot; host=myapp.herokuapp.com request_id=310ac45a-3657-4c5f-96dc-f0a1350429db fwd=&quot;93.146.33.170&quot; dyno=web.1 connect=1ms service=10ms status=302 bytes=371 protocol=http</p>
  </blockquote>
  <blockquote>
  <p>2021-02-18T10:34:03.321194+00:00 app[web.1]: {</p>
  </blockquote>
  <blockquote>
  <p>2021-02-18T10:34:03.321209+00:00 app[web.1]: id: 'XXX',</p>
  </blockquote>
  <blockquote>
  <p>2021-02-18T10:34:03.321210+00:00 app[web.1]: displayName: 'XXX',</p>
  </blockquote>
  <p>Backend logs when login goes bad:</p>
  <blockquote>
  <p>2021-02-18T10:36:29.284759+00:00 heroku[router]: at=info method=GET path=&quot;/auth/google&quot; host=myapp.herokuapp.com request_id=2f56f65b-9236-4710-b029-dd973ec0c9a3 fwd=&quot;54.187.137.25&quot; dyno=web.1 connect=0ms service=3ms status=302 bytes=371 protocol=http</p>
  </blockquote>
  <blockquote>
  <p>nothing else</p>
  </blockquote>
  <p>Any ideas? Could you help me?</p>
  <p>Thank you.</p>