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

**URL:** <https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418>\
**Category:** PragProg Customers\
**Tags:** book-web-development-with-clojure-third-edition, suggestion\
**Created:** [15 August 2021 05:48 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418 "2021-08-15T05:48:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pm9999](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pm9999](https://forum.devtalk.com/u/pm9999)\
**Post date:** [15 August 2021 05:48 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418/1 "2021-08-15T05:48:48Z")

</div>

@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`?

---

<div class="post-metadata">

**Author:** ![svmbrown](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/s/7ea924/32.png) [@svmbrown](https://forum.devtalk.com/u/svmbrown)\
**Post date:** [20 August 2021 00:06 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418/2 "2021-08-20T00:06:39Z")

</div>

That bug should be addressed by the custom session store we introduced on page 187.

We exposed access to the underlying `ttl-memory-store` so that we could access up-to-date authentication information in it from the websocket handler. This is because our websocket only has the initial HTTP request sent on connection, so the session information that would be unpacked by the default middleware would be stale.

---

<div class="post-metadata">

**Author:** ![pm9999](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pm9999](https://forum.devtalk.com/u/pm9999)\
**Post date:** [20 August 2021 00:12 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418/3 "2021-08-20T00:12:48Z")

</div>

I’m now onto page 244 and this issue is still there.

The way to reproduce in original post no longer works. Here’s a different way to reproduce:

1. login as user1
2. logout
3. login as user2
4. try to add a message

---

<div class="post-metadata">

**Author:** ![svmbrown](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/s/7ea924/32.png) [@svmbrown](https://forum.devtalk.com/u/svmbrown)\
**Post date:** [20 August 2021 00:46 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418/4 "2021-08-20T00:46:24Z")

</div>

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?

```auto
["/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.

---

<div class="post-metadata">

**Author:** ![pm9999](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@pm9999](https://forum.devtalk.com/u/pm9999)\
**Post date:** [20 August 2021 01:53 UTC](https://forum.devtalk.com/t/web-development-with-clojure-third-edition-bug-in-restrict-posting-to-authenticated-users-page-194/17418/5 "2021-08-20T01:53:01Z")

</div>

Problem solved. Empty map `{}` does the trick. Thank you.
