From 57bb0080262c1e7c972212fd19ce4ce2eb3e36c7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 5 Apr 2025 22:00:41 +0300 Subject: [PATCH] Update the routes to add authentication if needed. --- lib/decentralised_book_index_web/router.ex | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/decentralised_book_index_web/router.ex b/lib/decentralised_book_index_web/router.ex index 5dcc395..e1b96da 100644 --- a/lib/decentralised_book_index_web/router.ex +++ b/lib/decentralised_book_index_web/router.ex @@ -35,23 +35,7 @@ defmodule DecentralisedBookIndexWeb.Router do scope "/", DecentralisedBookIndexWeb do pipe_through :browser - live "/", BookLive.Index, :index - - live "/publishers", PublisherLive.Index, :index - live "/publishers/new", PublisherLive.Index, :new - live "/publishers/:id/edit", PublisherLive.Index, :edit - - live "/publishers/:id", PublisherLive.Show, :show - live "/publishers/:id/show/edit", PublisherLive.Show, :edit - - live "/servers", DbiServerLive.Index, :index - live "/servers/new", DbiServerLive.Index, :new - live "/servers/:id/edit", DbiServerLive.Index, :edit - - live "/servers/:id", DbiServerLive.Show, :show - live "/servers/:id/show/edit", DbiServerLive.Show, :edit - - ash_authentication_live_session :authenticated_routes do + ash_authentication_live_session :maybe_authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :live_user_optional} do # in each liveview, add one of the following at the top of the module: # # If an authenticated user must be present: @@ -63,19 +47,35 @@ defmodule DecentralisedBookIndexWeb.Router do # If an authenticated user must *not* be present: # on_mount {DecentralisedBookIndexWeb.LiveUserAuth, :live_no_user} - live "/books", BookLive.Index, :index - live "/books/new", BookLive.Edit, :new - live "/books/:id/edit", BookLive.Edit, :edit + live "/", BookLive.Index, :index + live "/books", BookLive.Index, :index live "/books/:id", BookLive.Show, :show - live "/books/:id/show/edit", BookLive.Show, :edit live "/authors", AuthorLive.Index, :index + live "/authors/:id", AuthorLive.Show, :show + end + + ash_authentication_live_session :authenticated_routes, on_mount: {DecentralisedBookIndexWeb.LiveUserAuth, :live_user_required} do + live "/books/new", BookLive.Edit, :new + live "/books/:id/edit", BookLive.Edit, :edit + live "/authors/new", AuthorLive.Edit, :new live "/authors/:id/edit", AuthorLive.Edit, :edit - live "/authors/:id", AuthorLive.Show, :show - live "/authors/:id/show/edit", AuthorLive.Show, :edit + live "/publishers", PublisherLive.Index, :index + live "/publishers/new", PublisherLive.Index, :new + live "/publishers/:id/edit", PublisherLive.Index, :edit + + live "/publishers/:id", PublisherLive.Show, :show + live "/publishers/:id/show/edit", PublisherLive.Show, :edit + + live "/servers", DbiServerLive.Index, :index + live "/servers/new", DbiServerLive.Index, :new + live "/servers/:id/edit", DbiServerLive.Index, :edit + + live "/servers/:id", DbiServerLive.Show, :show + live "/servers/:id/show/edit", DbiServerLive.Show, :edit end end