sodapopcan
Testing a LiveView form with csrf token
I’ve found a bunch of info on what I’m about to ask here but all a little vague. Or at least, the answers are direct but lack the context I’m looking for.
In a nutshell, is it necessary to manually render the csrf_token in a LiveView form, or does LiveView already handle csrf verification?
If the answer is “yes”, are there testing facilities for this? Using the standard ConnCase along with importing LiveViewTest doesn’t send the token through the setup context.
Thanks!
example:
defmodule MyApp.PageLive do
use MyApp, :live_view
def mount(_, %{"_csrf_token" => csrf_token}, socket) do
changeset = MyApp.Context.changeset_something()
{:ok,
socket
|> assign(:csrf_token, csrf_token)
|> assign(:changeset, changeset)}
end
def render(assigns) do
~L"""
<%= f = form_for @changeset, "#", phx_submit: "something-changed", csrf_token: @csrf_token %>
<%= submit f, "Submit" %>
</form>
"""
end
def handle_event("something-changed", socket) do
# ...
{:noreply, socket}
end
end
Most Liked
sodapopcan
Ehn, I realized what I did. I had submit "Change email instead of submit f, "Change email. D’oh.
1
Popular in Discussions
After doing a port from a c++ library to my project in phoenix I’ve seen that I need a faster way to run this algorithm and I found this ...
New
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them?
Feel free to be as concise or in-depth as you li...
New
I’ve been hearing much about the new formatter and it’s something I have been keen to try.
I find examples buy far the most illuminating...
New
Please, let me know if this kind of discussion already took place in another topic
.
Hi all, how do you consider if is better to build ...
New
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages.
It also goes on to call Elix...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
I suppose this question is effectively hackney vs. ibrowse but we are at a point in our project where we have to make a choice between th...
New
Hello everyone!
A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
What configs will make sense to put to runtime.exs?
–
A bit of how I configure apps:
I have generic configs in config/config.exs,
dev...
New
Other popular topics
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








