pm9999

pm9999

Web Development with Clojure, Third Edition: bug in Restrict Posting to Authenticated Users? (page 194)

@Dmitri @svmbrown

At the end of Restrict Posting to Authenticated Users, I think there’s a bug but I’m not able to find any solution.

Consider this scenario, an user loads the page without logging in, then after staying on the same page, logging in and trying to post will leads to error "Please log in before posting". I’m able to see that it’s the direct result of websocket.clj returning {:unauthorized true} to client and it triggers the :form/set-server-errors.

Does this have anything to do with open websocket remains unauthenticated after browser successfully visits /login?

Marked As Solved

svmbrown

svmbrown

Author of Web Development with Clojure

I think I might know what it is, but I can’t reproduce it at the moment because I don’t have the full codebase handy on this computer. Could you try changing the /logout handler in guestbook.routes.services to set the session to an empty map instead of nil like so?

["/logout"
    {:post {:handler
            (fn [_]
              (->
               (response/ok)
               (assoc :session {})))}}]

I believe that setting it to nil is completely blowing away the ttl-memory-store so that we end up with a new session ID when we hit /login again, but the websocket still has the stale session ID.

If this is the problem, the “proper” way to solve it would be to keep the nil server-side, but to have the client refresh/redirect to / so that all client-side state is re-instantiated as well.

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
Mmm
Hi, build fails on: bracket-lib = “~0.8.1” when running on Mac Mini M1 Rust version 1.5.0: Compiling winit v0.22.2 error[E0308]: mi...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
AstonJ
Or looking forward to? :nerd_face:
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New

Sub Categories: