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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use Future;
use NewSession;
use crate;
/// Consumer-provided account resolution.
///
/// Called during OAuth callback to resolve the PAS identity to a local user account.
/// The returned [`UserId`] is stored in the session.
///
/// # Example
///
/// ```rust,ignore
/// impl AccountResolver for MyAdapter {
/// type Error = MyError;
///
/// async fn resolve(
/// &self,
/// ppnum_id: &PpnumId,
/// ppnum: &Ppnum,
/// ) -> Result<UserId, MyError> {
/// let user = self.repo.find_by_ppnum_id(ppnum_id).await?
/// .unwrap_or(self.repo.create(ppnum_id).await?);
/// Ok(UserId(user.id.to_string()))
/// }
/// }
/// ```
/// Consumer-provided session persistence.
///
/// Sessions are identified by [`SessionId`] (opaque string wrapper).
/// The consumer chooses the ID format (ULID, UUID, etc.).
///
/// The `AuthContext` associated type lets consumers return their own auth type
/// from `find()`, eliminating the need for parallel auth middleware.
///
/// # Example
///
/// ```rust,ignore
/// impl SessionStore for MyAdapter {
/// type Error = MyError;
/// type AuthContext = MyAuthUser; // your handler's auth type
///
/// async fn create(&self, session: NewSession) -> Result<SessionId, MyError> {
/// let id = Ulid::new().to_string();
/// self.db.insert_session(&id, &session).await?;
/// Ok(SessionId(id))
/// }
///
/// async fn find(&self, session_id: &SessionId) -> Result<Option<MyAuthUser>, MyError> {
/// // Return your full auth context directly
/// self.db.find_session_with_context(session_id).await
/// }
///
/// async fn delete(&self, session_id: &SessionId) -> Result<(), MyError> {
/// self.db.delete_session(session_id).await
/// }
/// }
/// ```