@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 +1 -1
- package/src/common-hooks.mjs +8 -6
- package/src/index.mjs +1 -0
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -44,10 +44,12 @@ export function protect(field) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
export async function
|
|
48
|
-
if (context.transport
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
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
|
}
|