@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 +1 -1
- package/src/common-hooks.mjs +4 -9
- package/src/context.mjs +12 -8
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
data:
|
|
14
|
-
|
|
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) {
|