1

I've tried a couple different iterations but I keep getting this error when compiling:

Routes.session_path/2 is undefined (module Routes is not available)

My Code:

defmodule Blackbook.Plugs.RequireAuth do
    import Plug.Conn
    import Phoenix.Controller
    alias Blackbook.Router.Helpers, as: Routes

    def init(_params) do
    end

    def call(conn, _params) do
        if conn.assigns[:current_user] do
            conn
        else
            conn
            |> put_flash(:error, "You must be logged in.")
            |> redirect(to: Routes.session_path(conn, :new))
            |> halt()
        end
    end
end

It's a little different in Phoenix 1.4, tried referring to documentation here https://hexdocs.pm/phoenix/Phoenix.Router.html but still no luck.

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
Nathan
  • 239
  • 3
  • 15

1 Answers1

5

Since you're using , it creates a separate YourAppWeb namespace for web-related modules by default. In your case, I believe it's just a typo and it should be this:

alias BlackbookWeb.Router.Helpers, as: Routes

(Note the Web part)

Sheharyar
  • 73,588
  • 21
  • 168
  • 215