@jcbuisson/express-x 1.6.2 → 1.6.4

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.2",
3
+ "version": "1.6.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -1,19 +1,15 @@
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
8
+ export const hashPassword = (passwordField) => async (context) => {
12
9
  context.args[0][passwordField] = await bcrypt.hash(context.args[0][passwordField], 5)
13
10
  return context
14
11
  }
15
12
 
16
-
17
13
  // remove `field` from `result`
18
14
  export function protect(field) {
19
15
  return async (context) => {
@@ -28,12 +24,11 @@ export function protect(field) {
28
24
  }
29
25
  }
30
26
 
31
-
32
27
  export async function isAuthenticated(context) {
33
28
  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`)
29
+ // extract sessionId from connection data
30
+ const sessionId = await getConnectionDataItem(context, 'sessionId')
31
+ if (!sessionId) throw Error(`Not authenticated (no sessionId in connection data)`)
37
32
  }
38
33
 
39
34
  export const isNotExpired = async (context) => {
package/src/context.mjs CHANGED
@@ -6,14 +6,18 @@ export async function getContextConnection(context) {
6
6
  }
7
7
 
8
8
  export async function resetConnection(context) {
9
- const id = context.params.connectionId
10
- await context.app.prisma.Connection.update({
11
- where: { id },
12
- data: {
13
- data: '{}',
14
- channelNames: '[]',
15
- }
16
- })
9
+ try {
10
+ const id = context.params.connectionId
11
+ await context.app.prisma.Connection.update({
12
+ where: { id },
13
+ data: {
14
+ data: '{}',
15
+ channelNames: '[]',
16
+ }
17
+ })
18
+ } catch(err) {
19
+ console.log('should not happen', err)
20
+ }
17
21
  }
18
22
 
19
23
  export async function getConnectionDataItem(context, key) {