@jcbuisson/express-x 1.6.3 → 1.6.5
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 +6 -10
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
|
|
2
|
-
import config from 'config'
|
|
3
2
|
import bcrypt from 'bcryptjs'
|
|
4
3
|
|
|
5
4
|
import { getConnectionDataItem } from './context.mjs'
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
// hash password of user record
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
context.args[0][passwordField] = await bcrypt.hash(context.args[0][passwordField], 5)
|
|
8
|
+
export const hashPassword = (passwordField) => async (context) => {
|
|
9
|
+
// context.result is a user
|
|
10
|
+
context.result[passwordField] = await bcrypt.hash(context.result[passwordField], 5)
|
|
13
11
|
return context
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
17
14
|
// remove `field` from `result`
|
|
18
15
|
export function protect(field) {
|
|
19
16
|
return async (context) => {
|
|
@@ -28,12 +25,11 @@ export function protect(field) {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
|
|
32
28
|
export async function isAuthenticated(context) {
|
|
33
29
|
if (context.transport !== 'ws') return
|
|
34
|
-
// extract
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
30
|
+
// extract sessionId from connection data
|
|
31
|
+
const sessionId = await getConnectionDataItem(context, 'sessionId')
|
|
32
|
+
if (!sessionId) throw Error(`Not authenticated (no sessionId in connection data)`)
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
export const isNotExpired = async (context) => {
|