@jcbuisson/express-x 1.5.0 → 1.5.1

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.0",
3
+ "version": "1.5.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -44,10 +44,12 @@ export function protect(field) {
44
44
  }
45
45
 
46
46
 
47
- export async function setSessionJWT(context) {
48
- if (context.transport === 'ws') {
49
- // associate JWT token to WS connection to mark it as secure
50
- context.connection.accessToken = context.result.accessToken
51
- }
52
- return context
47
+ export async function isAuthenticated(context) {
48
+ if (context.transport !== 'ws') return
49
+ // extract user from connection data
50
+ const id = context.params.connectionId
51
+ const connection = await context.app.service('Connection')._findUnique({ where: { id }})
52
+ const data = JSON.parse(connection.data)
53
+ const user = data.user
54
+ if (!user) throw Error(`AuthCode hook: not authenticated ${id}`)
53
55
  }
package/src/index.mjs CHANGED
@@ -7,4 +7,5 @@ export {
7
7
 
8
8
  hashPassword,
9
9
  protect,
10
+ isAuthenticated,
10
11
  }