@driveflux/auth 4.0.53 → 4.0.54-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ import { PrismaAdapter } from './prisma-adapter.js';
16
16
  const useSecureCookies = config.auth.secureCookies;
17
17
  const adapter = PrismaAdapter();
18
18
  const MAX_AGE = 30 * 24 * 60 * 60;
19
+ const LAST_ACTIVITY_UPDATE_THROTTLE_MINUTES = 30;
19
20
  const nextAuthUrl = process.env.NEXTAUTH_URL;
20
21
  if (!nextAuthUrl) {
21
22
  throw new Error('NEXTAUTH_URL is not set');
@@ -144,7 +145,7 @@ export const authOptions = {
144
145
  }
145
146
  return true;
146
147
  },
147
- async session ({ session, user, trigger, token, ...others }) {
148
+ async session ({ session, user, trigger }) {
148
149
  const { password, permissions, stripeCustomerId, ...newUser } = {
149
150
  ...user
150
151
  };
@@ -178,6 +179,33 @@ export const authOptions = {
178
179
  finalSession.newSessionToken = newSessionToken;
179
180
  }
180
181
  }
182
+ // Update user's last activity, but throttle to avoid database overload
183
+ // Only update if last activity was more than THROTTLE_MINUTES ago
184
+ // Using updateMany with a WHERE clause ensures atomicity and prevents
185
+ // unnecessary writes even with concurrent requests
186
+ try {
187
+ const threshold = new Date(Date.now() - LAST_ACTIVITY_UPDATE_THROTTLE_MINUTES * 60 * 1000);
188
+ await prisma.session.update({
189
+ where: {
190
+ id: session.id,
191
+ OR: [
192
+ {
193
+ lastActiveAt: null
194
+ },
195
+ {
196
+ lastActiveAt: {
197
+ lt: threshold
198
+ }
199
+ }
200
+ ]
201
+ },
202
+ data: {
203
+ lastActiveAt: new Date()
204
+ }
205
+ });
206
+ } catch (_e) {
207
+ // Silently fail
208
+ }
181
209
  return finalSession;
182
210
  }
183
211
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/auth",
3
- "version": "4.0.53",
3
+ "version": "4.0.54-next.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -75,7 +75,7 @@
75
75
  "@casl/ability": "^6.7.3",
76
76
  "@casl/prisma": "^1.5.2",
77
77
  "@driveflux/config": "3.0.8",
78
- "@driveflux/db": "4.0.29",
78
+ "@driveflux/db": "4.0.30-develop.0",
79
79
  "@driveflux/fetch": "8.0.0",
80
80
  "@driveflux/problem": "6.0.0",
81
81
  "@driveflux/reporter": "7.0.1",