@jcbuisson/express-x 1.5.26 → 1.5.28
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/common-hooks.mjs +10 -4
- package/src/context.mjs +0 -1
- package/src/server.mjs +2 -2
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import config from 'config'
|
|
3
3
|
import bcrypt from 'bcryptjs'
|
|
4
4
|
|
|
5
|
-
import { getConnectionDataItem } from './context.mjs'
|
|
5
|
+
import { getConnectionDataItem, resetConnection } from './context.mjs'
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// hash password of user record
|
|
@@ -36,9 +36,15 @@ export async function isAuthenticated(context) {
|
|
|
36
36
|
if (!userId) throw Error(`Not authenticated`)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export const isNotExpired =
|
|
39
|
+
export const isNotExpired = async (context) => {
|
|
40
40
|
if (context.transport !== 'ws') return
|
|
41
|
-
const
|
|
41
|
+
const expireAtISO = await getConnectionDataItem(context, 'expireAt')
|
|
42
|
+
const expireAt = new Date(expireAtISO)
|
|
42
43
|
const now = new Date()
|
|
43
|
-
if (expireAt > now)
|
|
44
|
+
if (expireAt > now) {
|
|
45
|
+
// clear connection data
|
|
46
|
+
await resetConnection(context)
|
|
47
|
+
// throw exception
|
|
48
|
+
throw new Error('session expired')
|
|
49
|
+
}
|
|
44
50
|
}
|
package/src/context.mjs
CHANGED
package/src/server.mjs
CHANGED
|
@@ -384,10 +384,10 @@ export function expressX(prisma, options = {}) {
|
|
|
384
384
|
app.log('verbose', `publish channels ${service.name} ${action} ${channelNames}`)
|
|
385
385
|
for (const channelName of channelNames) {
|
|
386
386
|
app.log('verbose', `service-event ${service.name} ${action} ${channelName}`)
|
|
387
|
-
const connectionList = getChannelConnections(channelName)
|
|
387
|
+
const connectionList = await getChannelConnections(channelName)
|
|
388
388
|
for (const connection of connectionList) {
|
|
389
389
|
app.log('verbose', `emit to ${connection.id} ${service.name} ${action} ${result}`)
|
|
390
|
-
const socket = cnx2Socket
|
|
390
|
+
const socket = cnx2Socket[connection.id]
|
|
391
391
|
socket.emit('service-event', {
|
|
392
392
|
name: service.name,
|
|
393
393
|
action,
|