polypush135
Heres the error.
1) test checks if account is active authenticated?/2 halts if account is no longer active (Beffect.Plugs.AuthTest)
test/beffect/plug/auth_test.exs:7
** (ArgumentError) flash not fetched, call fetch_flash/2
code: |> Beffect.Plugs.Auth.authenticated?(%{})
stacktrace:
(phoenix) lib/phoenix/controller.ex:1228: Phoenix.Controller.get_flash/1
(phoenix) lib/phoenix/controller.ex:1210: Phoenix.Controller.put_flash/3
(beffect) lib/beffect/plugs/auth.ex:30: Beffect.Plugs.Auth.authenticated?/2
test/beffect/plug/auth_test.exs:17: (test)
FYI lib/beffect/plugs/auth.ex:30 is the puts_flash
heres the test
test "authenticated?/2 halts if account is no longer active" do
user = insert(:user, active: false)
conn = build_conn()
|> init_test_session(user_id: user.id)
|> assign(:current_user, user)
|> bypass_through(BeffectWeb.Router, :browser) # ? not sure if its really calling that pipeline
|> Beffect.Plugs.Auth.authenticated?(%{})
assert get_flash(conn, :error) =~ "Your account is no longer active"
assert redirected_to(conn) =~ "/login"
end
Heres Beffect.Plugs.Auth.authenticated?
def authenticated?(conn, _opts) do
cond do
conn.assigns.current_user && conn.assigns.current_user.active ->
conn
conn.assigns.current_user ->
assign(conn, :current_user, nil)
conn
|> put_flash(:error, "Your account is no longer active") # Setting the flash here
|> redirect(to: Helpers.session_path(conn, :new,origin_path: conn.request_path))
|> halt()
...
end
Heres the pipeline for :brower
pipeline :browser do
....
plug :fetch_flash # calling it here....
...
end
Also note that I IO.puts in the pipeline to see if its called and it looks as if it is being called.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mgwidmann
Looks to me like it is working. You’re skipping the
:browserpipeline, and as expected theflashis not fetched. Maybe you need to separate out your basic browser needs from your authentication needs.chrismccord
bypass_throughwill only invoke the pipeline when you send a request against the router, so your tests should work with the following:(note, you don’t need
init_test_sessionsince bypass_through will fetch the session in your browser pipeline:polypush135
I totally missed what
“but you need to invoke the Endpoint plugs and :browser pipeline of your Router for session and flash related dependencies” meant.
Maybe a update to the doc that calls out that what the use of get(“/”) is doing in that case. ( Just a thought. )
chrismccord
Great opportunity for a PR
Maybe before the
## Examplesmake a note about a request being sent with get and friends is required to invoke the pipeline(s)?polypush135
Just about to ask if thats something I could do but then found it for me self. Will do
polypush135
Opensource FTW
https://github.com/phoenixframework/phoenix/pull/2633