R
R
Rozhden2019-07-05 14:33:56
Node.js
Rozhden, 2019-07-05 14:33:56

How to save cookies on the Node.js server transmitted via API from the server to php?

I can not immediately paint everything correctly, so write I will supplement the question as fully as possible.
Input data. There are:
1. API in PHP.
2. Server on Node.js
3. Client side on React.js
My actions and where the error occurs:
1. First I need to get a CSRF token. I get it on the Node.js server, along with all the data:

server:Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_fcgid/2.3.9 PHP/7.3.0
strict-transport-security:max-age=31536000; preload
x-powered-by:PHP/7.3.0
expires:Thu, 19 Nov 1981 08:52:00 GMT
cache-control:no-store, no-cache, must-revalidate
pragma:no-cache
access-control-allow-headers:Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With
access-control-allow-methods:GET,HEAD,POST,PUT,DELETE,OPTIONS
access-control-allow-credentials:true
content-type:application/json
date:Fri, 05 Jul 2019 11:26:37 GMT
content-length:103
connection:keep-alive
set-cookie:PHPSESSID=907f9cace36ee999fea00c736f4367b1; path=/,cookie_hash=KaY3uShg25OUQVnTxyva2w6LLosuBT4K; expires=Thu, 31-Dec-2037 23:00:00 GMT; Max-Age=583587203; path=/

2. Next, you need to make the following request (any), in my case, this is a list of services.
I send a request, but I get a response that the token is invalid.
What I did:
1. I checked which token I'm getting.
2. I checked which token I am passing on the second request. It matches the received, everything is ok.
3. Before this, the project worked without server rendering, purely communication: React > Api. And everything worked. Now there is a need for server rendering, and I still do not understand where the problem is.
In my understanding, I'm receiving cookies via the API, which are not stored on the Node.js server.
If I understand correctly, then tell me how to save them correctly?
If I'm wrong, please tell me what. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-07-05
@inoise

You have two different servers. It is logical to use something more universal for the exchange. For example, jwt tokens

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question