Add authorised routes with tests
This commit is contained in:
parent
37985ac1cf
commit
8590df5032
6 changed files with 131 additions and 1 deletions
lib/real_estate_web
18
lib/real_estate_web/live/admin_dashboard_live.ex
Normal file
18
lib/real_estate_web/live/admin_dashboard_live.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule RealEstateWeb.AdminDashboardLive do
|
||||
use RealEstateWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
socket = assign_defaults(session, socket)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~L"""
|
||||
<section class="phx-hero">
|
||||
<h1>Welcome to the admin dashboard!</h1>
|
||||
</section>
|
||||
"""
|
||||
end
|
||||
end
|
18
lib/real_estate_web/live/user_dashboard_live.ex
Normal file
18
lib/real_estate_web/live/user_dashboard_live.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule RealEstateWeb.UserDashboardLive do
|
||||
use RealEstateWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
socket = assign_defaults(session, socket)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~L"""
|
||||
<section class="phx-hero">
|
||||
<h1>Welcome to the user dashboard!</h1>
|
||||
</section>
|
||||
"""
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
defmodule RealEstateWeb.Router do
|
||||
use RealEstateWeb, :router
|
||||
|
||||
import RealEstateWeb.UserAuth
|
||||
alias RealEstateWeb.EnsureRolePlug
|
||||
|
||||
pipeline :browser do
|
||||
plug :accepts, ["html"]
|
||||
|
@ -17,6 +17,14 @@ defmodule RealEstateWeb.Router do
|
|||
plug :accepts, ["json"]
|
||||
end
|
||||
|
||||
pipeline :user do
|
||||
plug EnsureRolePlug, [:admin, :user]
|
||||
end
|
||||
|
||||
pipeline :admin do
|
||||
plug EnsureRolePlug, :admin
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
# scope "/api", RealEstateWeb do
|
||||
# pipe_through :api
|
||||
|
@ -73,4 +81,16 @@ defmodule RealEstateWeb.Router do
|
|||
post "/users/confirm", UserConfirmationController, :create
|
||||
get "/users/confirm/:token", UserConfirmationController, :confirm
|
||||
end
|
||||
|
||||
scope "/", RealEstateWeb do
|
||||
pipe_through [:browser, :require_authenticated_user, :user]
|
||||
|
||||
live "/user_dashboard", UserDashboardLive, :index
|
||||
end
|
||||
|
||||
scope "/", RealEstateWeb do
|
||||
pipe_through [:browser, :require_authenticated_user, :admin]
|
||||
|
||||
live "/admin_dashboard", AdminDashboardLive, :index
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue