I have a project where users can create a one time key in a LiveView UI. When they do this I want to trigger a download of a small text file with the private one-time key so they can’t accidentally lose it, but I also don’t want to (even temporarily) persist the private key to the filesystem on the server. I’m looking for the best/simplest way to do this with current Phoenix and LiveView.
I’ve already googled how to do file downloads and the results I get are a little confusing, because I think the available options especially from a LiveView seem to have changed over time. My understanding is basically you have to redirect the browser to a controller with an GET action to do the download, and there are different ways to do the redirect which have different impacts to either keeping the LiveView process running or not. I’ve prototyped that and can at least send a text file with send_download/3, but I’m unsure how to get the key I generated in the LiveView process into the controller. I’m considering something with a named ETS table that the LiveView process writes the data into, and the download controller reads from. Even with that I’m not sure how to associate the download to the specific LiveView session it was redirected from (I don’t want User1 to get User2’s key for example). At this point I’m now a little unsure if I might be headed in the wrong direction entirely.
I’m very inexperienced with web development and Elixir so please bear with me if this question seems poorly formulated… I’d really appreciate any suggestions (or examples!) about good approaches to do this. Thanks!