Pow 注册视图一直显示不正确的 html 文件

问题描述 投票:0回答:0

我正在开发一个基于这篇文章的聊天网络应用程序项目:https://curiosum.com/blog/elixir-phoenix-liveview-messenger-part-3。我已经到达了实现用户授权的部分,并且遇到了一个奇怪的问题。根据文章及其 github 表示,一切都已正确设置。有两个按钮 - “注册”和“注册”分别指向 /session/new/registration/new。他们的 html 表示在路径 lib/chat_web/templates/pow/session/new.html.eexlib/chat_web/templates/pow/registration/new.html.eex 中,因为它们应该是。但是当我按下这些按钮时,它们会不断将我重定向到同一个 html 页面,即 lib/chat_web/templates/layout/app.html.eex。如果我删除了 new.html.eex 文件,重定向最终会出现 Could not render "new.html" 错误,这表明路由是正确的。我真的不知道我是这个问题的原因。链接到我的存储库中的分支:https://github.com/ArturMarekNowak/Chat/tree/wip/authorization

/lib/chat_web/templates/layout/app.html.eex

<%= if Pow.Plug.current_user(@conn) do %>
  <li><%= link "Profile", to: Routes.pow_registration_path(@conn, :edit) %></li>
  <li><%= link "Sign out", to: Routes.pow_session_path(@conn, :delete), method: :delete %></li>
<% else %>
  <li><%= link "Register", to: "/registration/new" %></li>
  <li><%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %></li>
<% end %>

/lib/chat_web/router.ex

defmodule ChatWeb.Router do
  use ChatWeb, :router
  use Pow.Phoenix.Router
  import Phoenix.LiveView.Router

  pipeline :browser do
    plug(:accepts, ["html"])
    plug(:fetch_session)
    plug(:fetch_live_flash)
    plug(:protect_from_forgery)
    plug(:put_secure_browser_headers)
    plug(:put_root_layout, {ChatWeb.LayoutView, :root})
  end

  pipeline :api do
    plug(:accepts, ["json"])
  end

  pipeline :protected do
    plug(Pow.Plug.RequireAuthenticated,
      error_handler: Pow.Phoenix.PlugErrorHandler
    )
  end

  scope "/" do
    pipe_through(:browser)

    pow_routes()
  end

  scope "/", ChatWeb do
    pipe_through(:browser)

    get("/", PageController, :index)
  end

  # Make conversation routes protected by requiring authentication
  scope "/", ChatWeb do
    pipe_through([:browser, :protected])

    resources("/conversations", ConversationController)

    live("/conversations/:conversation_id/users/:user_id", ConversationLive, as: :conversation)
  end
end

/lib/chat_web/views/pow/session_view.ex

defmodule ChatWeb.Pow.SessionView do
  use ChatWeb, :view
end

/lib/chat_web/templates/pow/session/new.html.eex

<h1>Register</h1>

<%= form_for @changeset, @action, [as: :user], fn f -> %>
  <%= if @changeset.action do %>
    <div class="alert alert-danger">
      <p>Oops, something went wrong! Please check the errors below.</p>
    </div>
  <% end %>

  <%= label f, Pow.Ecto.Schema.user_id_field(@changeset) %>
  <%= text_input f, Pow.Ecto.Schema.user_id_field(@changeset) %>
  <%= error_tag f, Pow.Ecto.Schema.user_id_field(@changeset) %>

  <%= label f, :nickname %>
  <%= text_input f, :nickname %>
  <%= error_tag f, :nickname %>

  <%= label f, :password %>
  <%= password_input f, :password %>
  <%= error_tag f, :password %>

  <%= label f, :confirm_password %>
  <%= password_input f, :confirm_password %>
  <%= error_tag f, :confirm_password %>

  <div>
    <%= submit "Register" %>
  </div>
<% end %>


<span><%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %></span>

html elixir
© www.soinside.com 2019 - 2024. All rights reserved.