Skip to content

new phx.gen.auth ... choosing LiveView fails to inject menu items in layouts #5176

@kEND

Description

@kEND

Environment

  • Elixir version (elixir -v): Elixir 1.14.0 (compiled with Erlang/OTP 25)
  • Phoenix version (mix deps): phoenix 1.7.0-rc.0 aead257
  • Operating system: macOS 12.3.1

Goal: try out the new LiveView-based auth on a blank 1.7.0-rc.0 project.

  1. mix phx.new dev_app and follow prompts to get deps and create a database.
  2. mix phx.gen.auth Accounts User users choosing 'Y' for LiveView based system.

Expected behavior

Do you want to create a LiveView based authentication system? [Yn] Y
* creating priv/repo/migrations/20221222005622_create_users_auth_tables.exs
* creating lib/dev_app/accounts/user_notifier.ex
...

dev_app/ ~

Actual behavior

The auth menu items are not injected into the layout files.

* injecting lib/dev_app_web/router.ex - plug

Unable to find an application layout file to inject user menu items.

Missing files:

  * lib/dev_app_web/templates/layout/root.html.heex
  * lib/dev_app_web/templates/layout/app.html.heex

Please ensure this phoenix app was not generated with
--no-html. If you have changed the name of your application
layout file, please add the following code to it where you'd
like the user menu items to be rendered.

    <ul>
      <%= if @current_user do %>
        <li>
          <%= @current_user.email %>
        </li>
        <li>
          <.link href={~p"/users/settings"}>Settings</.link>
        </li>
        <li>
          <.link href={~p"/users/log_out"} method="delete">Log out</.link>
        </li>
      <% else %>
        <li>
          <.link href={~p"/users/register"}>Register</.link>
        </li>
        <li>
          <.link href={~p"/users/log_in"}>Log in</.link>
        </li>
      <% end %>
    </ul>


Please re-fetch your dependencies with the following command:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions