C
C
connecter2019-08-05 13:53:33
JavaScript
connecter, 2019-08-05 13:53:33

What is the best way to set cookies?

The question is, when sending a request to the server and a successful response, return the cookie value in the response and set the value on the client via document.cookie, or indicate in the response itself that it is necessary to set cookies via res.cookie(...)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-08-05
@connecter

It depends on what you are going to write there and depending on where this data is needed.
If this is data that is used only by the client and the server does not use it in any way, then it is better through document.cookie. Otherwise, res.cookie.
Token and other confidential data for identification, in a good way, write to the HttpOnly cookie on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question