What would be the best approach to have an auto-redirect for a user that is logged in already, so X user logs in, then close the site but then comes back it, he should be redirected to the admin/dashboard. I’m using Coherence and Coherence Assent. I’m thinking this should be done in the router but not sure how
Here is my current router
defmodule MagnifyWeb.Router do
use MagnifyWeb, :router
use Coherence.Router
use CoherenceAssent.Router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug Coherence.Authentication.Session
end
pipeline :protected do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
plug Coherence.Authentication.Session, protected: true
end
pipeline :admin_layout do
plug :put_layout, {MagnifyWeb.LayoutView, :admin}
end
scope "/" do
pipe_through :browser
coherence_routes()
coherence_assent_routes()
end
scope "/" do
pipe_through :protected
coherence_routes :protected
end
scope "/", MagnifyWeb do
pipe_through :browser # Use the default browser stack
get "/", HomeController, :index
get "/about", AboutController, :index
end
scope "/", MagnifyWeb do
pipe_through [:protected, :admin_layout]
# add protected resources below
resources "/dashboard", DashboardController
resources "/magnets", MagnetController
end
pipeline :api do
plug :accepts, ["json"]
end
end