* Called when a session is created for a user. * Creates the user record if it doesn't exist yet; increments sessionCount.
(userId: string, meta?: { email?: string; name?: string })
| 22 | * Creates the user record if it doesn't exist yet; increments sessionCount. |
| 23 | */ |
| 24 | touch(userId: string, meta?: { email?: string; name?: string }): void { |
| 25 | const existing = this.users.get(userId); |
| 26 | if (existing) { |
| 27 | existing.lastSeenAt = Date.now(); |
| 28 | existing.sessionCount += 1; |
| 29 | if (meta?.email && !existing.email) existing.email = meta.email; |
| 30 | if (meta?.name && !existing.name) existing.name = meta.name; |
| 31 | } else { |
| 32 | this.users.set(userId, { |
| 33 | id: userId, |
| 34 | email: meta?.email, |
| 35 | name: meta?.name, |
| 36 | firstSeenAt: Date.now(), |
| 37 | lastSeenAt: Date.now(), |
| 38 | sessionCount: 1, |
| 39 | }); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Called when a session is destroyed for a user. |
no test coverage detected