Set cookies in LiveView?

Is there a way to call Conn.put_resp_cookie/4? There is no need to turn liveview into a traditional controller function.

One way I think of is to pass data through assign and execute Javascript when re-rendering? But I think it’s best not to be like this.


Finally, I bind the cookie data to a DOM attribute, then execute the Javascript code via updated Hook, read and write.

:see_no_evil:Is there a better way?

1 Like

That’s probably the best way, the issue with trying to do it any other way is that if you get to that page via live_link then there is no HTTP request done that would let you set the cookie the normal way.