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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews