ArturMarekNowak

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

enter image description here

/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>

Showing Posts 1 to 3

BradS2S

BradS2S

I was expecting to see controller files here: chat_web/controllers/pow/.
Something like this:


defmodule Pow.Phoenix.RegistrationController do
  use Pow.Phoenix.Controller

  def process_new(conn, _params) do
    {:ok, :response, conn}
  end

  def respond_new({:ok, :response, conn}) do
    render(conn, "new.html")
  end
end
ArturMarekNowak

ArturMarekNowak OP

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

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews