A
A
Alexander Vasilenko2017-09-30 07:51:07
go
Alexander Vasilenko, 2017-09-30 07:51:07

How to pass cookies from a server written in Golang to a ReactJS application if there is CORS between them?

There was a problem. There is a server application written in Go that performs API functions. And there is a ReactJS application. They are located at different addresses, respectively, they have CORS. Well, so be it, allowed such a relationship between them, but it is assumed that Go passes the cookie to the browser and then uses this state for further actions. And the cookie is passed to the browser if we just pull the appropriate request through the browser. But from a React application, the same request does not lead to such a result. Response received, but no cookie. It's all about CORS.
Here's what to do - I don't know. Maybe I'm going in the wrong direction? Maybe you need to generate a cookie in the React application based on some data received from the server? Should I use JWT? Give a hint.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
F
Frimko, 2017-09-30
@Frimko

in order for the browser to save the cookies that the server sends us. 4 headers required
to send cookies in your requests you must check

withCredentials: true

in Jquery in $.ajax it is added as a parameter
$.ajax({
xhrFields: { withCredentials: true },
});

N
Nikita, 2017-09-30
@bitver

It googles.

X
xmoonlight, 2017-09-30
@xmoonlight

Wrap the API in a React application - mount it on the same server (so that the domain address is the same) and that's it.

O
Oleg Gamega, 2017-09-30
@gadfi

at one time, I just turned off security in the browser for development, I don’t know if it will start with your backend, but it should)
supposed to help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question