From c9eda03a7a7c340fefd402bd1984096ca7684af3 Mon Sep 17 00:00:00 2001 From: Vladislav Oleshko Date: Mon, 4 Jul 2022 12:59:33 +0300 Subject: [PATCH] Update docs --- docs/guides/included-middleware.md | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/docs/guides/included-middleware.md b/docs/guides/included-middleware.md index 03f00ce37..a56cfb3c6 100644 --- a/docs/guides/included-middleware.md +++ b/docs/guides/included-middleware.md @@ -18,18 +18,17 @@ Session data can be stored in multiple ways: __Always list the CookieParser before the Session__ ```cpp -using Session = crow::SessionMiddleware; -crow::App app {Session{ - "MY_SECRET_KEY", - crow::InMemoryStore{} +using Session = crow::SessionMiddleware; +crow::App app{Session{ + crow::FileStore{"/tmp/sessiondata"} }}; ``` -Session ids are stored in cookies and are signed with a secret key. After the key changes, all cookies are invalidated. Check the example for more details about expiration management and customization. +Session ids are represented as random alphanumeric strings and are stored in cookies. See the examples for more customization options. ### Usage -A session is basically a key-value map with support for multiple types: strings, integers, booleans and doubles. +A session is basically a key-value map with support for multiple types: strings, integers, booleans and doubles. The map is created and persisted automatically as soon it is first written to. ```cpp auto& session = app.get_context(request); @@ -51,14 +50,6 @@ session.apply("views", [](int v){return v + 1;}); // this operation is always at session.mutex().lock(); // manually lock session ``` -The session is created as soon as it is written to, but we can check whether it already exists. -We can also request a specific id for the session when it is created. This is only useful for custom stores that will support equal ids on multiple clients. Because the cookie is signed, any id is secure. -```cpp -if (!session.exists()) { - session.preset_id(user_email); -} -``` - ### Expiration Expiration can happen either by the cookie expiring or the store deleting "old" data.