ArturMarekNowak
I am working on a project which is a chat web application based on this article: Phoenix LiveView Tutorial: Build a Live Chat App from Scratch | Curiosum. I have reached the part where user authorization is implemented and I have encourted a weird problem. According to the article and it’s github representation everything is set up properly. There are two buttons - “sign up” and “register” leading to /session/new and /registration/new respectively. Their html representations are in paths lib/chat_web/templates/pow/session/new.html.eex and lib/chat_web/templates/pow/registration/new.html.eex as they should be. But when I press those buttons they keep redirecting me to the same html page which is lib/chat_web/templates/layout/app.html.eex. If I delete and of the new.html.eex files redirection ends up in Could not render “new.html” error which suggests to me that routing is correct. I really am out of ideas what my be the cause of this problem. Link to branch in my repository: GitHub - ArturMarekNowak/Chat at wip/authorization · GitHub
/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>
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
BradS2S
I was expecting to see controller files here: chat_web/controllers/pow/.
Something like this:
ArturMarekNowak
Thank you for your answer Brad. Isn’t it what you typed just an extension? The Pow documentation names your example as “MyPowExtension.Phoenix.MyController” whereas Pow should posses and apply Pow.Phoenix.RegistrationController by default ?
BradS2S
I’m by no means an expert on Pow. I was just going off the normal pattern of where things ideally go In Phoenix.
It appears to me that nothing is happening because there’s nothing in place to tell it to do anything.