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.
I'm using the http.Redirect function and already try: - 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. - 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. - Create a new request and send it through the redirect function once again. This also doesn't work.
That's the code I use with the SetCookie function, which is the one that work out the best:
strToken := CreateToken(user)
urlAuthRedirect := "https://komfy.now.sh"
cookie := http.Cookie{
Name: "jwt-token",
Value: strToken,
}
http.SetCookie(resp, &cookie)
http.Redirect(
resp, // ResponseWriter
req, // Request
urlAuthRedirect,
http.StatusSeeOther)
Does any of you guys have an idea in order to pass the cookie from the authentication endpoint to the home page ?