@jcbuisson/express-x 1.5.24 → 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.24",
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
  }
package/src/server.mjs CHANGED
@@ -9,7 +9,7 @@ import express from 'express'
9
9
  export function expressX(prisma, options = {}) {
10
10
 
11
11
  const app = express()
12
- app.set('prisma', prisma)
12
+ // app.set('prisma', prisma)
13
13
 
14
14
  if (options.ws === undefined) options.ws = { ws_prefix: "expressx" }
15
15
 
@@ -434,6 +434,7 @@ export function expressX(prisma, options = {}) {
434
434
 
435
435
  // enhance `app` with objects and methods
436
436
  return Object.assign(app, {
437
+ prisma,
437
438
  options,
438
439
  cnx2Socket,
439
440
  createDatabaseService,