1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use SessionMiddleware;
use ;
use RedisSessionStore;
use Key;
use ExposeSecret;
use SecretString;
/// Connect to Redis and create a session store.
///
/// Must be called once during microservice startup before constructing the Actix-Web app.
/// Pass the returned store to [`session_middleware`].
///
/// # Parameters
/// - `redis_uri` — connection URI for the Redis instance (e.g. `redis://127.0.0.1:6379`).
/// Wrapped in [`SecretString`] so the URI (which may contain credentials) is never
/// accidentally printed to logs.
///
/// # Errors
/// Returns an error if the Redis connection cannot be established at startup.
pub async
/// Build the Actix-Web session middleware backed by Redis.
///
/// Call this once per microservice and register the result with `.wrap(…)` on the
/// Actix-Web [`App`](actix_web::App).
///
/// Session behaviour:
/// - **Persistent sessions** with TTL extended on every request (`OnEveryRequest`),
/// so active users are never unexpectedly logged out.
/// - `cookie_http_only(false)` — allows JavaScript to read the session cookie (required
/// by the Angular front-end for token refresh flows).
/// - `cookie_secure(false)` — permits HTTP in development; set to `true` in production
/// behind TLS.
///
/// # Parameters
/// - `hmac_secret` — secret used to sign the session cookie. Must be at least 64 bytes;
/// loaded from configuration and wrapped in [`SecretString`] to prevent accidental
/// logging.
/// - `redis_store` — the store returned by [`redis_session`].