title: plug in phoenix controller
body: <p>I'm writing a sample app to Phoenix framework.
  my authenticate.ex:</p>
  
  <pre><code>defmodule Myapp.Plug.Authenticate do
    import Plug.Conn
    import Myapp.Router.Helpers
    import Phoenix.Controller
  
    def init(default), do: default
  
    def call(conn, default) do
      current_user = get_session(conn, :current_user)
      if current_user do
        assign(conn, :current_user, current_user)
      else
        conn
          |&gt; put_flash(:error, 'You need to be signed in to view this page')
          |&gt; redirect(to: session_path(conn, :new))
      end
    end
  end
  </code></pre>
  
  <p>there is a controller in which I do not require authentication for a single action:</p>
  
  <pre><code>defmodule Myapp.SharedLinkController do
    use Myapp.Web, :controller
    alias Myapp.SharedLink
  
    plug Myapp.Plug.Authenticate when action in [:new, :create]
  
  ...
  
  end
  </code></pre>
  
  <p>it works, but the problem is that there is a menu display depends on whether the user is authorized or not:</p>
  
  <pre><code>&lt;%= if Map.has_key?(@conn.assigns, :current_user) do %&gt;
    &lt;li&gt;first&lt;/li&gt;
  &lt;% else %&gt;
    &lt;li&gt;second&lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>and it turns out that on the page action, which I do not require authentication, I get that a user is not authorized, even when it is authorized. how can I solve this problem?</p>