@jcbuisson/express-x 2.1.16 → 2.1.17
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.
- package/package.json +1 -1
- package/src/index.mjs +18 -4
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -358,11 +358,13 @@ export const isNotExpired = async (context) => {
|
|
|
358
358
|
context.socket.leave(room)
|
|
359
359
|
}
|
|
360
360
|
// send an event to the client (typical client handling: logout)
|
|
361
|
-
context.socket.emit('
|
|
361
|
+
context.socket.emit('not-authenticated')
|
|
362
362
|
// throw exception
|
|
363
363
|
throw new EXError('not-authenticated', "Session expired")
|
|
364
364
|
}
|
|
365
365
|
} else {
|
|
366
|
+
// send an event to the client (typical client handling: logout)
|
|
367
|
+
context.socket.emit('not-authenticated')
|
|
366
368
|
throw new EXError('not-authenticated', "No expiresAt in socket.data")
|
|
367
369
|
}
|
|
368
370
|
}
|
|
@@ -373,8 +375,16 @@ export const isNotExpired = async (context) => {
|
|
|
373
375
|
export const isAuthenticated = async (context) => {
|
|
374
376
|
// do nothing if it's not a client call from a ws connexion
|
|
375
377
|
if (context.caller !== 'client') return
|
|
376
|
-
if (!context.socket?.data)
|
|
377
|
-
|
|
378
|
+
if (!context.socket?.data) {
|
|
379
|
+
// send an event to the client (typical client handling: logout)
|
|
380
|
+
context.socket.emit('not-authenticated')
|
|
381
|
+
throw new EXError('not-authenticated', 'no data in socket')
|
|
382
|
+
}
|
|
383
|
+
if (!context.socket.data?.user) {
|
|
384
|
+
// send an event to the client (typical client handling: logout)
|
|
385
|
+
context.socket.emit('not-authenticated')
|
|
386
|
+
throw new EXError('not-authenticated', 'no user in socket.data')
|
|
387
|
+
}
|
|
378
388
|
}
|
|
379
389
|
|
|
380
390
|
/*
|
|
@@ -383,6 +393,10 @@ export const isAuthenticated = async (context) => {
|
|
|
383
393
|
export const extendExpiration = (duration) => async (context) => {
|
|
384
394
|
const now = new Date()
|
|
385
395
|
if (context.caller !== 'client') return
|
|
386
|
-
if (!context.socket?.data)
|
|
396
|
+
if (!context.socket?.data) {
|
|
397
|
+
// send an event to the client (typical client handling: logout)
|
|
398
|
+
context.socket.emit('not-authenticated')
|
|
399
|
+
throw new EXError('not-authenticated', 'no data in socket')
|
|
400
|
+
}
|
|
387
401
|
context.socket.data.expiresAt = new Date(now.getTime() + duration)
|
|
388
402
|
}
|