 
  		        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 Pragmatic Bookshelf topics
                         
                      
                       
           
           
           
           
           
           
           
           
           
          Other popular topics
                         
                      
                       
           
           
           
           
           
           
           
           
           
          Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /rails
- /js
- /security
- /go
- /swift
- /vim
- /clojure
- /haskell
- /emacs
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /crystal
- /c-plus-plus
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /opensuse
- /html
- /centos
- /php
- /zig
- /deepseek
- /scala
- /lisp
- /sublime-text
- /textmate
- /react-native
- /nixos
- /debian
- /agda
- /kubuntu
- /arch-linux
- /django
- /revery
- /ubuntu
- /deno
- /spring
- /manjaro
- /nodejs
- /diversity
- /lua
- /julia
- /c
- /slackware
 
    





