I am new to Phoenix and having a problem with Phoenix 1.8.0-rc.3 and the new user scope when using generated resources.
When I use the generator to create a new Phoenix app called scope
,
$ mix phx.new scope
then create a LiveView based authentication system,
$ mix phx.gen.auth Accounts User users
then create a scoped LiveView resource
$ mix phx.gen.live Curriculum Level levels name:string difficulty:integer
and add the generated live rules to router.ex so that the request goes through the :browser
pipeline that contains the plug :fetch_current_scope_for_user
scope "/", ScopeWeb do
pipe_through(:browser)
get("/", PageController, :home)
live("/levels", LevelLive.Index, :index)
live("/levels/new", LevelLive.Form, :new)
live("/levels/:id", LevelLive.Show, :show)
live("/levels/:id/edit", LevelLive.Form, :edit)
end
and then start the app and navigate to /levels
,
I get the following error:
[error] ** (KeyError) key :current_scope not found in: %{__changed__: %{}, flash: %{}, live_action: :index}
I left out the obvious steps of fetching dependencies and creating and migrating the database.
I must be doing something wrong, but cannot find what causes the problem.
Both branches of the fetch_current_scope_for_user/2
plug defined in user_auth.ex assign :current_scope
, so it should be in the assigns?
I am essentially just following along the video on this site, only with a different version of Phoenix: Elixir learning: A first look at Phoenix scopes
Any help appreciated, thanks!