This was achieved by setting the cookie with code on grails side as
Cookie cookie = new Cookie('userNameCookie', fullname); cookie.setVersion(-1) // unknown version bypasses quoting logic cookie.path = "/" cookie.maxAge = 30 * 60 * 60; //30 minutes life response.addCookie(cookie)
However, there was an issue with this approach. The usernames could have unicode characters like ä, ö etc. The cookie was not getting set from the grails application and threw an Exception because the unicode characters weren’t escaped. The exception also suggested that we could use decodeBase64(). But since it was due to encode, we decided to convert the fullname to bytes, encode it to base64, call the toString() method and then set the value. What we did was to change the cookie value to from grails
Cookie cookie = new Cookie('usercookie', fullname.bytes.encodeBase64().toString());
In order to decode this base64 encoded string on the client side, we used the jQuery Base 64 Functions plugin. This can be used to decode a base64 encoded string as
This worked like a charm.
Hope this helps