romenigld
Hello Guys,
first all I’m loving this book and it’s very helpfull.
I am reading now the version P1.0 of the ebook.
But I was in the part of ‘Log Out’ the session and I notice there they isn’t using a put_flash . And I would like to inform with a message.
So I try to put this:
def delete(conn, _) do
conn
|> RumblWeb.Auth.logout()
|> put_flash(:info, "Bye, Bye!")
|> redirect(to: Routes.page_path(conn, :index))
end
And when I test in the browser, this doesn’t shows the flash message.
Why this occur? It’s why we are dropping the session?
I’m asking just for clarify.
And another question is, why in the plug RumblWeb.Auth.logout don’t uses the clear_session(conn) like this:
def logout(conn) do
conn
|≥ clear_session()
|≥ configure_session(drop: true)
end
I’m asking because I saw using this in another example and why don’t was used here?
![]()
And in other part of the book:
If you want to keep the session around, you could also delete only the user ID information by calling
delete_session(conn, :user_id).
This part I don’t know why it was confusing and I want to understand better. In which cases this will serve for example? can Anyone explain better?
I’ll appreciate! ![]()
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
peerreynders
https://media.pragprog.com/titles/phoenix14/code/authentication/listings/rumbl/lib/rumbl_web/controllers/session_controller.change2.ex
If you use:
You should see this in the server console
when you log out.
Phoenix.Controller.redirect/2So what is happening is that
redirect/2is instructing the browser to request “/” - the index page prepared bypage_controller.ex.The
connstructure used forRumblWeb.PageController.index/2is a fresh, new value. Whatever you put into theconnbefore the HTTP redirection has been lost …https://media.pragprog.com/titles/phoenix14/code/authentication/listings/rumbl/lib/rumbl_web/controllers/auth.change2.ex
Plug.Conn.configure_session/2… and in the absence of a session nothing carries over from one request to the next.
Plug.Conn.clear_session/1i.e. given that the session is being dropped, clearing it is redundant.
Now change to this:
and this
and you will see the flash info on the index page when you log out.
Plug.Conn.delete_session/2simply deletes the value associated with the:user_idkey from the session - but the rest of the session and all the other data in it remains - which is why now the flash info can carry over to the index page.Ankhers
Minor nitpick, but you can write this as
peerreynders
IO.inspect/2returns the value that it inspects - which can be useful in pipelines but here I have no interest in a return value and I want to directly annotate what is being output (thoughIO.inspecthas the:labeloption).romenigld
Nice explanation @peerreynders, thank you very much for reply.
I’m loving the power of the Phoenix Framework.
I’ll expect to be very good using this framework.
And It’s a lot of things to learn… And I expect more books for learn with phoenix using the phoenix live view or react and vuejs.