I am using phx_gen_auth
for user sign in, signup, authentication in my Elixir Phoenix application. It comes with a :require_authenticated_user
plug to decide if a specific route requires the user to be authenticated before accessing.
If I have a resource of posts in my router.ex
that gives me all the standard actions:
resources "/posts", PostController
How can I best organize certain routes to require the user to be signed in? For example, viewing all of the posts or viewing a single post shouldn't require login. But creating, editing, updating, deleting a post should require the user to be signed in.
Is there a way to manage which routes require auth without specifying all of my routes separately in two separate scope
blocks that have separate pipe_through
s?