How would you write an authorization plug for LiveViews?

I wrote a custom authorization plug that I’m using in most of my controllers like this:

plug Authorization, [domain: :users, at_least: :manage]

How would you write such a plug in a LiveView? (directly mounted as a live route, no controller)

1 Like

Everything related to websockets doesn’t use plugs at all.

Ok, so what would be the way to go then?

Either check access in the plug pipeline before the mounted live view or handle it somehow in the lifeview’s code. The latter would take care that changes in access are taken into consideration on each mount and not only on page refresh.

1 Like