
pm9999
Web Development with Clojure, Third Edition: bug in Restrict Posting to Authenticated Users? (page 194)
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
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










Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /lua
- /nodejs
- /julia
- /slackware
- /c
- /neovim