Forum Discussion

Payal's avatar
Payal
Director
7 years ago

Create cookie in page initialization script returns log in issue

Hi Everyone,

 

Few days back, I tried to create a new browser cross domain cookie on the response and used http.response.setCookie(cookie) context object in page initialization script. Then after that, I was not able to log in to the community and ultimately, i opened a ticket with support to revert the old version. So, basically i am unable to figure out, what's the reason behind this?

 

Thanks,

Payal Uppal

  • The Common.init file can easily break your site. It's possible something with your code was slightly off, and that led to you losing access to all parts of the site (since it is in Common.init).

     

    Here's what I've used to set cookies in Common.init without any issues:

     

        <#assign newCookie = http.request.createCookie("cookieName", "value") />
        ${newCookie.setMaxAge(28800)} <#--8 hours-->
        ${newCookie.setPath("/")}
        ${http.response.addCookie(newCookie)}