Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSRF cookie #7

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/inertia_phoenix/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule InertiaPhoenix.Plug do
def call(conn, _) do
conn
|> check_inertia_req
|> put_csrf_cookie
|> check_assets_version
end

Expand All @@ -19,17 +20,15 @@ defmodule InertiaPhoenix.Plug do
|> put_resp_header("vary", "accept")
|> put_resp_header("x-inertia", "true")
|> assign(:inertia_request, true)
|> put_csrf_cookie

_ ->
conn
|> assign(:inertia_request, false)
|> put_csrf_cookie
end
end

defp put_csrf_cookie(conn) do
conn |> put_resp_cookie("XSRF-TOKEN", Controller.get_csrf_token())
conn |> put_resp_cookie("XSRF-TOKEN", Controller.get_csrf_token(), http_only: false)
end

defp check_assets_version(conn) do
Expand Down