| 112 | }; |
| 113 | |
| 114 | const updateUserLastActiveAt = (user: UserWithAccounts) => { |
| 115 | const now = Date.now(); |
| 116 | if ( |
| 117 | user.lastActiveAt && |
| 118 | (now - user.lastActiveAt.getTime()) < LAST_ACTIVE_AT_THRESHOLD_MS |
| 119 | ) { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | // Fired without a await to avoid blocking. |
| 124 | void __unsafePrisma.user |
| 125 | .update({ |
| 126 | where: { id: user.id }, |
| 127 | data: { lastActiveAt: new Date(now) }, |
| 128 | }) |
| 129 | .catch(() => { /* updaing the lastActiveAt is best effort. */ }); |
| 130 | }; |
| 131 | |
| 132 | type AuthSource = 'session' | 'oauth' | 'api_key'; |
| 133 | |