I have a simple delete button in my UI, and when the user clicks it I want to delete the database record and redirect to their profile.
def handle_event("delete", _params, socket) do
if socket.assigns.current_user.id == socket.assigns.list.user_id do
{:ok, _list} = Lists.delete_list(socket.assigns.list)
end
socket =
socket
|> redirect(to: ~p"/users/#{socket.assigns.current_user.slug}")
{:noreply, socket}
end
This is deleting the record properly, but for some reason the mount/3
callback is being called and of course the record no longer exists so I get all kinds of errors.
(app 0.1.0) lib/app_web/live/list_live/show.ex:246: AppWeb.ListLive.Show.mount/3
How can I redirect to the user profile without re-running the expensive mount/3
call?