I have a LiveView that allows a logged-in user to modify his settings (name, password, etc.). Each of the fields that allows modification is implemented as a dedicated Live Component with its own state. The Live Components are presented in a modal view from the parent component.
I pass the redirect path to the Live Component, which then performs the update actions (querying external API if applicable and updating the local database).
Since the Live Components are presented modally, I was using push_patch/2
to patch to the parent LiveView and using send()
to pass the updated user to the parent’s handle_info/3
callback, which would then set socket.assigns.current_user
of the LiveView to include the changes that were made.
My concern was that this could theoretically introduce a security hole since it would skip requires_authenticated_user
via the mount
callback. Or, at the very least that the database might diverge from what is displayed in the front-end.
So, I’ve replaced the call to push_patch/2
with one to push_navigate/2
on a successful user modification (I still use push_patch/2
on an unsuccessful one).
My question is whether this was necessary or whether it would be okay to stick with push_patch/2
. Were my security concerns valid? Are there other considerations? What is the best practice here?