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
58
59
60
61
62
63
64
65
66
67
68
//! Long-lived, unsigned, client-writable preference cookies - backing
//! `@globals`' `persist` entries (`persist theme = "dark"`, see
//! `docs/MACROS.md`). Deliberately **not** the session cookie
//! (`session.rs`): that one is scoped to the current browser session
//! (`Expiry::OnSessionEnd` by default - no `.with_expiry(...)` call
//! anywhere in this crate) and rotates on every login
//! (`Session::cycle_id()`, see `larust_auth::guard::login`) - the wrong
//! lifetime for a preference that should survive both. Also deliberately
//! **not** signed/encrypted (`axum_extra`'s `PrivateCookieJar`/
//! `SignedCookieJar`): tampering with your own theme preference has no
//! security consequence, so the `Key`-management complexity those add
//! isn't worth it here.
//!
//! Read-only from the server's side, by design - the write path is the
//! browser setting `document.cookie` directly (the same "no server round
//! trip for a purely-local UI preference" reasoning already applies to a
//! plain client-side toggle), not a POST endpoint this module would need
//! to expose. See `demo/resources/views/layouts/app.blade.xr`'s
//! theme-toggle script for the real write side.
pub use CookieJar;
/// Every persisted-preference cookie is named `larust_pref_{name}` - keeps
/// this whole category of cookie visibly distinct (in devtools, in a
/// cookie-consent audit) from the session cookie or any future unrelated
/// app cookie, and impossible to collide with either.
/// Reads a `persist` global's current value - `None` when the browser
/// never set it (a first visit, or the user cleared cookies), in which
/// case the `@globals` block's own fallback expression is what actually
/// renders. See `larust_macros`'s `Node::PersistGlobal` codegen arm, the
/// only caller this function is really designed for.