I have a modal form_component (generated by phx.gen.live). The liveview that kicks off the form_component is available to all users. But I want that form_component to require authentication via phx.gen.auth functionality. The problem is that the form_component doesn’t have a route that I can put under pipe_through [:browser, :require_authenticated_user]
Use Case is very similar to Pinterest: User is searching resources that anyone can view. They click on a link to “Save” the resource to a personal library of resources. User can have multiple libraries. Once they click “Save”, I want the user to be presented with a form_component that just asks them to select what library they want to save the resource to. But that requires authentication for only the form_component not the parent Liveview.
Possible Solution: I use a handle_event for “Save” to check for authentication and force user to authenticate if not logged in. Once authenticated, I kick off the form_component. Is that the best way to do this? Can I force authentication from inside the LiveView? I normally just doing it via the routes.