6

I am creating a websocket upgrade request in javascript and need to add a cookie for adding an authentication token, is this possible with cross domain restrictions? My implementation is pretty basic:

document.cookie="token="+authToken+";domain=www.test.com;path=/";
websocket = new WebSocket(endpoint);

1 Answer 1

1

You should change the way how you set the cookies value. There is no way to add the domain and path values of the cookies, they are added automatically. You should add just the nameOfProperty and valueOfProperty. See the simple example below:

 document.cookie = "FirstProperty=FirstPropertyValue";
 document.cookie = "SecondProperty=SecondPropertyValue";

 const ws = new WebSocket('ws://localhost:2427/health');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.