Skip to content

Commit

Permalink
Fix bug in plug pipelines
Browse files Browse the repository at this point in the history
This prevented the MethodOverride plug from working, which allows us to make links that have a `DELETE` method for example.

Also update the logout button to use delete.
  • Loading branch information
mveytsman committed Jun 17, 2024
1 parent 88dc0cd commit 476928b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/bike_brigade_web/components/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule BikeBrigadeWeb.Layouts do
My Profile
</.sidebar_link>
<.sidebar_link selected={@current_page == :logout} href={~p"/logout"} method="post">
<.sidebar_link selected={@current_page == :logout} href={~p"/logout"} method="delete">
<:icon>
<Heroicons.arrow_left_on_rectangle solid />
</:icon>
Expand Down
5 changes: 5 additions & 0 deletions lib/bike_brigade_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ defmodule BikeBrigadeWeb.Endpoint do
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
Expand Down
11 changes: 1 addition & 10 deletions lib/bike_brigade_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ defmodule BikeBrigadeWeb.Router do
plug :get_user_from_session
end

pipeline :parse_request do
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
end

pipeline :browser do
plug :parse_request
plug :accepts, ["html"]
plug :sessions
plug :fetch_live_flash
Expand All @@ -46,7 +38,6 @@ defmodule BikeBrigadeWeb.Router do
end

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

Expand Down Expand Up @@ -110,7 +101,7 @@ defmodule BikeBrigadeWeb.Router do
live "/leaderboard", StatsLive.Leaderboard, :show
end

post "/logout", Authentication, :logout
delete "/logout", Authentication, :logout
end

scope "/", BikeBrigadeWeb do
Expand Down

0 comments on commit 476928b

Please sign in to comment.