@jcbuisson/express-x 1.5.25 → 1.5.26

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.5.25",
3
+ "version": "1.5.26",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -36,7 +36,9 @@ export async function isAuthenticated(context) {
36
36
  if (!userId) throw Error(`Not authenticated`)
37
37
  }
38
38
 
39
- export const isExpired = (delay) => async (context) => {
39
+ export const isNotExpired = (delay) => async (context) => {
40
40
  if (context.transport !== 'ws') return
41
- // TODO
41
+ const expireAt = await getConnectionDataItem(context, 'expireAt')
42
+ const now = new Date()
43
+ if (expireAt > now) throw new Error('session expired')
42
44
  }
package/src/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { expressX } from './server.mjs'
3
- import { hashPassword, protect, isAuthenticated } from './common-hooks.mjs'
3
+ import { hashPassword, protect, isAuthenticated, isNotExpired } from './common-hooks.mjs'
4
4
  import { getContextConnection, resetConnection, getConnectionDataItem, setConnectionDataItem, removeConnectionDataItem, sendServiceEventToClient } from './context.mjs'
5
5
 
6
6
  export {
@@ -18,4 +18,5 @@ export {
18
18
  hashPassword,
19
19
  protect,
20
20
  isAuthenticated,
21
+ isNotExpired,
21
22
  }