@live-change/user-service 0.9.213 → 0.9.215
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/authenticator.js +21 -13
- package/package.json +4 -4
package/authenticator.js
CHANGED
|
@@ -5,17 +5,17 @@ import definition from './definition.js'
|
|
|
5
5
|
|
|
6
6
|
import { User, AuthenticatedUser } from './model.js'
|
|
7
7
|
|
|
8
|
+
const SLOW_QUERY_MS = 500
|
|
9
|
+
|
|
8
10
|
definition.authenticator({
|
|
9
11
|
name: 'user',
|
|
10
|
-
async credentialsObservable(credentials) {
|
|
11
|
-
console.log('[auth] credentialsObservable start', {
|
|
12
|
-
name: 'user',
|
|
13
|
-
session: credentials.session,
|
|
14
|
-
ip: credentials.ip
|
|
15
|
-
})
|
|
12
|
+
async credentialsObservable(credentials) {
|
|
16
13
|
return app.dao.observable(
|
|
17
14
|
['database', 'queryObject', app.databaseName, `(${
|
|
18
|
-
async (input, output, { session, authenticatedTableName, userTableName }) => {
|
|
15
|
+
async (input, output, { session, authenticatedTableName, userTableName, slowQueryMs }) => {
|
|
16
|
+
const queryId = (Math.random()*10000).toFixed(0)
|
|
17
|
+
const ts = () => new Date().toISOString()
|
|
18
|
+
//output.debug(ts(), queryId, 'STARTING USER AUTH QUERY', { session })
|
|
19
19
|
const authenticatedTable = input.table(authenticatedTableName)
|
|
20
20
|
const userTable = input.table(userTableName)
|
|
21
21
|
let user = null
|
|
@@ -23,10 +23,10 @@ definition.authenticator({
|
|
|
23
23
|
let userObserver = null
|
|
24
24
|
let oldCredentials = null
|
|
25
25
|
await authenticatedTable.object(session).onChange(async (authData, oldAuthData) => {
|
|
26
|
-
output.debug("NEW USER AUTH", authData, "FROM", oldAuthData)
|
|
27
26
|
const newUser = authData ? authData.user : null
|
|
27
|
+
//output.debug(ts(), queryId, "AUTH DATA CHANGE TO", authData, "FROM", oldAuthData, "NEW USER", newUser, "OLD USER", user)
|
|
28
28
|
if(newUser === user) return
|
|
29
|
-
output.debug("USER CHANGE", user, '=>', newUser)
|
|
29
|
+
//output.debug(ts(), queryId, "USER CHANGE", user, '=>', newUser)
|
|
30
30
|
if(user) {
|
|
31
31
|
if(userObject) {
|
|
32
32
|
await userObject.unobserve(userObserver)
|
|
@@ -38,13 +38,14 @@ definition.authenticator({
|
|
|
38
38
|
user = newUser
|
|
39
39
|
userObject = userTable.object(user)
|
|
40
40
|
const currentUserObject = userObject
|
|
41
|
+
//output.debug(ts(), queryId, "USER ON CHANGE START", { user })
|
|
41
42
|
await userObject.onChange(async (userData, oldUserData) => {
|
|
42
43
|
const newCredentials = userData ? {
|
|
43
44
|
id: user,
|
|
44
45
|
user,
|
|
45
46
|
roles: userData.roles
|
|
46
47
|
} : null
|
|
47
|
-
output.debug("NEW CREDENTIALS", newCredentials)
|
|
48
|
+
//output.debug("NEW CREDENTIALS", newCredentials)
|
|
48
49
|
output.change(newCredentials, oldCredentials)
|
|
49
50
|
oldCredentials = newCredentials
|
|
50
51
|
}).then(observer => {
|
|
@@ -54,19 +55,26 @@ definition.authenticator({
|
|
|
54
55
|
currentUserObject.unobserve(observer)
|
|
55
56
|
}
|
|
56
57
|
})
|
|
58
|
+
//output.debug(ts(), queryId, "USER ON CHANGE END", { user })
|
|
57
59
|
} else {
|
|
58
|
-
output.debug("USER NULL", user)
|
|
59
|
-
output.debug("OLD CREDENTIALS", oldCredentials)
|
|
60
|
+
//output.debug("USER NULL", user)
|
|
61
|
+
//output.debug("OLD CREDENTIALS", oldCredentials)
|
|
60
62
|
user = null
|
|
61
63
|
output.change(null, oldCredentials)
|
|
62
64
|
oldCredentials = null
|
|
63
65
|
}
|
|
64
66
|
})
|
|
67
|
+
//output.debug(ts(), queryId, "AUTH DATA ON CHANGE END", { session })
|
|
68
|
+
const ms = Date.now() - startedAt
|
|
69
|
+
if(ms >= slowQueryMs) {
|
|
70
|
+
output.debug('user auth query slow', { session, ms })
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
})`, {
|
|
67
74
|
session: credentials.session,
|
|
68
75
|
authenticatedTableName: AuthenticatedUser.tableName,
|
|
69
|
-
userTableName: User.tableName
|
|
76
|
+
userTableName: User.tableName,
|
|
77
|
+
slowQueryMs: SLOW_QUERY_MS
|
|
70
78
|
}]
|
|
71
79
|
)
|
|
72
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/user-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.215",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
26
|
-
"@live-change/relations-plugin": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.215",
|
|
26
|
+
"@live-change/relations-plugin": "^0.9.215",
|
|
27
27
|
"pluralize": "^8.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "d928600cde3212aa1c1ca1c167137b1658cb0275"
|
|
30
30
|
}
|