title: How to send cookie through redirection in golang?
body: <p>I'm working on an api, and after I authenticate an user, I would like to redirect him to the main page, passing through a cookie, which contain a jwt token.</p>
  <p>I'm using the <code>http.Redirect</code> function and I have already tried the following:</p>
  <ul>
  <li><p>Set the cookie to the ResponseWriter and send it through the redirect function but all it does it's setting a cookie on the authentication page but it doesn't pass it through the redirection, so the home page doesn't receive it.</p>
  </li>
  <li><p>Add the cookie to the request I first receive with the handler function and resent it through the redirect function. This doesn't work at all.</p>
  </li>
  <li><p>Create a new request and send it through the redirect function once again. This also doesn't work.</p>
  </li>
  </ul>
  <p>That's the code I use with the <code>http.SetCookie</code> function, which is the one that work out the best:</p>
  <pre class="lang-golang prettyprint-override"><code>strToken := CreateToken(user)
  urlAuthRedirect := &quot;https://komfy.now.sh&quot;
  
  cookie := http.Cookie{
      Name: &quot;jwt-token&quot;,
      Value: strToken, 
  }
  
  http.SetCookie(resp, &amp;cookie) 
  http.Redirect(
      resp, // ResponseWriter
      req, // Request
      urlAuthRedirect, 
      http.StatusSeeOther)
  </code></pre>
  <p>How do I pass the cookie from the authentication endpoint to the home page?</p>