-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ring session middleware #316
base: master
Are you sure you want to change the base?
Add ring session middleware #316
Conversation
modules/reitit-middleware/src/reitit/ring/middleware/session.clj
Outdated
Show resolved
Hide resolved
modules/reitit-middleware/src/reitit/ring/middleware/session.clj
Outdated
Show resolved
Hide resolved
modules/reitit-middleware/src/reitit/ring/middleware/session.clj
Outdated
Show resolved
Hide resolved
6c71b6b
to
cc073be
Compare
I might have misunderstood the usage of (def app
(ring/ring-handler
(ring/router
["/api"
{:session {:store nil}
:middleware [mw/session-middleware]}
["/ping" handler]
["/pong" handler]]))) |
I forgot about the |
Route data validation is not on by default, here's the guide: https://cljdoc.org/d/metosin/reitit/0.3.9/doc/ring/route-data-validation |
Document specs for the :session entity map. Fix the default session options. Add test to validate spec.
cc073be
to
f46244c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Please remove the stray .nrepl-port
file and then I'd be happy to merge this.
Recursively ignore .nrepl-port in the sub-directories.
One thing that comes to mind is that how should the middleware be configured. In reitit, there are options:
["/routes"
{:middleware [(session/session-middleware {:store xyz})]}
["/with-session!" ...]]
["/routes"
{:middleware [session/session-middleware]}
["/with-session!" ...]]
["/routes"
{:middleware [session/session-middleware]}
["/with-session!" {:session xyz} ...]
["/without-session!" ...]] would be good to have some coherence here. Just not sure what is the best way to do this. Comments? |
I agree that option 2 is not optimal, so this PR will to be fixed. My personal preference is option 3. I value the consistancy with other internal mw (option 3) more than the clarity from option 1. |
When `:session` key is absent in the route data, the session middleware will not be attached to the route. To enable the middleware, the user at least need to use an empty map `{}` for the `:session`, which uses the default options.
5152e46
to
a3c64ba
Compare
The commit a3c64ba changes from option 2 to option 3. I think we need some more feedbacks to make a decision. I think another reason to support option 3 (in general) is that the router code would be cleaner if anyone wants to have different configurations on routes. Say: ["/routes"
{:middleware [session/session-middleware]}
["/with-session-mem!" {:session {:store mem-store}} ...]
["/with-session-cookie!" {:session {:store cookie-store}} ...]
["/without-session!" ...]] Versus ["/routes"
["/with-session-mem!" {:middleware [(session/session-middleware {:store mem-store})]} ...]
["/with-session-cookie!" {:middleware [(session/session-middleware {:store cookie-store})]} ...]
["/without-session!" ...]] |
This PR addresses issue #205
Problem:
Solution: The
reitit.ring.middleware.session
ns shares one single store instance when the session store isn't specified from the user.Please let me know if there's anything that I can improve for this PR. Thank you!