title: How to send Oauth token from callback at the server to the client?
body: <p>I am using expressJs and passport for authentication. I am using Google Oauth2.0 for login with standard Passport GoogleStrategy. At client I am using axios for sending a login request to the server. My login routes are :</p>
  
  <pre><code>router.get(
      "/google",
      passport.authenticate("google", { scope: ["profile", "email"] }));
  
  router.get(
      "/google/callback",
      passport.authenticate("google", { failureRedirect: "/"}),
      function(req, res) {
  
          const token = jwt.sign({id: req.user.id}, configAuth.secretKey);
          console.log("generated token: ", token);
          res.json({success: true, token: 'bearer ' + token});
  
      }
  );
  </code></pre>
  
  <p>I am using the user information from the callback to generate the JWT which I want to sent the client.</p>
  
  <p>At the client I am using axios to send request and get the JWT and store it in localstore.</p>
  
  <pre><code>axios.get('http://localhost:3001/google')
    .then((result) =&gt; {
      console.log("result", result);
      localStorage.setItem('jwtToken', result.data.token);
    })
    .catch((error) =&gt; {
      // if(error.response.status === 401) {
      //   this.setState({ message: 'Login failed. Username or password not match' });
      // }
      console.log("Login error", error);
    });
  </code></pre>
  
  <p>But Axios doesn't wait for the redirect to happen and returns a HTML document with Loading... message. If you try to access the API in the browser, it returns the desired JSON object. Is there a way to wait for redirects. Should I use another library to send login request? </p>
  
  <p>I tried sending the token as url parameter with </p>
  
  <blockquote>
    <p>res.redirect()</p>
  </blockquote>
  
  <p>but client and server are at different ports so it doesn't work.
  Is there another way to do it?</p>