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
Elixir Upgrading is so Simple in Ubuntu and It worked for me
Ubuntu 16.04
git clone https://github.com/elixir-lang/elixir.git
cd elixir...
New
Hi everyone, im working on find best language/framework/system for
high concurrency, high performance and stable performance
after wor...
New
Hello,
I want to share a project I’ve been working on for a while:
https://github.com/almightycouch/gitgud
Background
Some time ago I ...
New
This is more of a general question, but I’m wondering how other people in the community think about the pattern matching in function sign...
New
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
Hi everyone,
I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New
If so I (and hopefully others!) might have some tips for you :slight_smile:
But first, please say which area you’re finding most challen...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things.
But I don’t think this is ...
New
Other popular topics
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
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
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
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
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








