FAQ
My cookie isn’t set, or get() returns an empty string
Section titled “My cookie isn’t set, or get() returns an empty string”Work through these in order:
- Look at
document.cookiein the browser console. Does setting it by hand work? - Set an explicit
path: '/'. Without one, the cookie belongs to the directory of the URL the page was loaded at. See Path and domain. - Leave
domainout onlocalhost. Browsers reject cookies whose domain doesn’t match the page. secure: true(also forced bysameSite: 'None'andpartitioned: true) needs HTTPS orlocalhost.- Check the browser console for an
[ngx-cookie-service]warning about a skipped or changed cookie.
delete() doesn’t remove my cookie
Section titled “delete() doesn’t remove my cookie”Pass the same path and domain the cookie was set with, plus partitioned: true for partitioned cookies. Cookies set by the server with HttpOnly can’t be deleted from the browser at all.
Cookies are empty during server-side rendering
Section titled “Cookies are empty during server-side rendering”CookieService only works in the browser. Use ngx-cookie-service-ssr, which reads the request’s Cookie header on the server.
I get a “token missing” or “no provider” error
Section titled “I get a “token missing” or “no provider” error”Usually a broken install. Reinstall your dependencies:
rm -rf node_modulesnpm installMy server can’t read the values
Section titled “My server can’t read the values”By default, values are URL-encoded, so a+b is stored as a%2Bb. If your server reads cookies without URL-decoding them, use provideCookieEncoding('minimal').
Further reading
Section titled “Further reading”- Using HTTP cookies on MDN
- Cookies on localhost with an explicit domain
- How do browser cookie domains work?
We can’t help with problems in other frameworks or back ends. For those, Stack Overflow is a better place to ask.