Can't set cookies on the client-side

I am currently developing a Jira cloud app using AC Spring Boot. I want to set cookies on the client-side based on user actions and send those cookies to the backend within the requests. However, I am facing difficulty in setting the cookies. They don’t appear in the Chrome DevTools and are not included in the requests. I have tried using various libraries such as js-cookie, jquery.cookie, and the document.cookie function, but none of them seem to work.

I have also attempted using the AP.cookie function, but it only writes data to localStorage instead of cookies.

Are there any restrictions on cookies for AC apps? If not, can you show me how to set a cookie on the client-side?

I assume you’re displaying your webpage in an iframe inside Jira, and your JavaScript on the same webpage sends some requests to your server.

Why do you want to use cookies to send data to server? For that you can use request body or request headers.

I want to render the iframe content differently on the server side based on some user settings that can be changed on the screen. Since Jira calls our endpoint to render the iframe, I can’t add the user’s remembered settings to the iframe request. Therefore, I am considering using cookies because they are automatically sent to the server with every request.

I was able to solve the issue. It turned out that what I needed was to include the SameSite option in my cookie settings. Once I added this option, I was able to successfully set cookies.

Here’s the code I used to set the cookie:

document.cookie = myCookie=myValue; SameSite=None; Secure; Max-Age=31536000;