title: how to secure a route for authenticated user only Elixir Phoenix
body: <p>I have created few routes in my application as</p>
  
  <pre><code>  scope "/", Socialistical do
      pipe_through :browser # Use the default browser stack
  
  
      get "/", UserController, :index
      get "/sign_up", UserController, :sign_up
      post "/create_user", UserController, :create
      options "/create_user", UserController, :nothing
  
      post "/session", SessionController, :create
      delete "/logout", SessionController, :delete
  
      get "/dashboard", DashboardController, :index
    end
  </code></pre>
  
  <p>As other routes than dashboard are those which could be available to the public. But I want to secure dashboard route for authenticated user only. I have created a session model as </p>
  
  <pre><code>defmodule Socialistical.Session do
    alias Socialistical.User
  
    def current_user(conn) do
      id = Plug.Conn.get_session(conn, :current_user)
      if id, do: Socialistical.Repo.get(User, id)
    end
  
    def logged_in?(conn), do: !!current_user(conn)
  end
  </code></pre>
  
  <p>I want to utilise these 2 methods for securing all coming routes which will be available for the authentic user only, Please help me in this. I am kind unaware how could  I make/convert it to plug. </p>