Skip to content

Commit

Permalink
Add csrf token component
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 16, 2024
1 parent 99958c2 commit f896e5f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/live_view_native/stylesheet/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ defmodule LiveViewNative.Stylesheet.Component do
<Style><%= @sheet %></Style>
"""
end

@doc """
Embed the CSRF token for LiveView as a tag
"""
def csrf_token(assigns) do
csrf_token = Phoenix.Controller.get_csrf_token()

assigns = Map.put(assigns, :csrf_token, csrf_token)
~LVN"""
<csrf-token value={csrf_token} />
"""
end
end

0 comments on commit f896e5f

Please sign in to comment.