title: Halt a connection after a redirect
body: <p>Inside a controller, I'm checking the session of the connection to verify if the session is attached to a user. If not, I redirect it to an other page.</p>
  
  <p><strong>But</strong> the <code>halt</code> returns me an error if I try to call it after the redirect:</p>
  
  <blockquote>
    <p>no function clause matching in Plug.Conn.halt/1</p>
  </blockquote>
  
  <p>And without the <code>halt</code> the page of the original controller does a render and print an error in the console (the template is rendered without a user):</p>
  
  <blockquote>
    <p>(exit) an exception was raised: (UndefinedFunctionError) undefined function: nil.username/0</p>
  </blockquote>
  
  <p><strong>So my question is</strong>: is it possible to call the <code>halt</code> after a redirect ?</p>
  
  <ul>
  <li>If yes, which part of my code is wrong ?</li>
  <li>If no, how can I prevent the controller to render the page ?</li>
  </ul>
  
  <p>Here's the code of my controller and the module used in it.</p>
  
  <pre><code>defmodule Mccm.DashboardController do
    use Mccm.Web, :controller
  
    import Mccm.Plug.Session
    import Mccm.Session, only: [current_user: 1]
  
    plug :needs_to_be_logged_in
  
    def index(conn, _params) do
      conn
      |&gt; render "index.html", user: current_user(conn)
    end
  end
  </code></pre>
  
  <hr>
  
  <pre><code>defmodule Mccm.Plug.Session do
    import Mccm.Session, only: [logged_in?: 1, is_teacher?: 1]
    import Phoenix.Controller, only: [redirect: 2]
    import Plug.Conn, only: [halt: 1]
  
    def needs_to_be_logged_in(conn, _) do
      if !logged_in?(conn) do
        conn
        |&gt; redirect to: "/"
        |&gt; halt # this give me an error
      else
        conn
      end
    end
  end
  </code></pre>
  
  <p>Here's dependencies used:</p>
  
  <ul>
  <li>phoenix: 1.0.2</li>
  <li>phoenix_ecto: 1.1</li>
  <li>phoenix_html: 2.1</li>
  <li>cowboy: 1.0</li>
  </ul>