Plug update parameter doesn't get reflected in liveview module

Currently we are storing SQL record id in continuous seq integer id, seq id get expose in URL path, so we have decided to encrypt and decrypt SQL id in URL…

To decrypt id, we have added plug to decrypt URL id’s in routes… decrypt plug logic work fine for controller code, but for live-view still it get encrypted parameters, looks like it doesn’t get decrypted id through plug or may be plug is executed for web-socket connection (please correct me if I am wrong)…

In Live-view phoenix create separate web-socket connection to handle user live event…looks like it have not using decrypt plug to decrypt value for web-socket connection

Thanks in advance

Hey @Satish welcome! You are correct, live view paths are not processed by plugs, so your plug isn’t going to run. Fortunately, LiveView has its own “middleware” idea that you can use to do the same thing:

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#on_mount/1

See the router based example for how to have an on_mount function called for all paths in the router.

Hey @benwilson512, Thank you for quick response!!!

Yes, in on_mount function I can run decrypt function for parameters, but not sure how to pass decrypted parameters to live-view…we know that on_mount function return tuple of {atom, socket} (it use to halt or continue connection)…(storing Parameters is socket not look good approach, it may break other functionality of live view like handle parameters etc)