@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -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
- // name of the password field is found in `config.authentication.local.passwordField` (default: 'password')
10
- export async function hashPassword(context) {
11
- const passwordField = config.authentication.local.passwordField
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 userId from connection data
35
- const userId = await getConnectionDataItem(context, 'userId')
36
- if (!userId) throw Error(`Not authenticated`)
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) => {