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.

Popular Prag Prog topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
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
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
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

siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
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

Latest in PragProg

View all threads ❯