I am trying to set a cookie that is permanent until changed

Sessions: are gone when the browser is closed

Cookie: Great for permanent data like a location. However, you can’t access cookies from the socket.

To safe-guard your application, Phoenix limits and validates the connection information your socket can access. This means your application is safe from these attacks, but you can’t access cookies and other headers in your socket.

The solution when using LiveView? Read the cookie in a conn plug, set it in the session and pick it up in the LiveView again.

LiveView access to cookies

Local storage: this is not send to the server but you might be able to preselect the right location with a Javascript hook. This saves you the hassle of a cookie read, session set and session get.

2 Likes