@live-change/user-service 0.2.8 → 0.2.13
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 +9 -3
- package/index.js +22 -10
- package/model.js +13 -0
- package/package.json +2 -2
- package/userItem.js +8 -2
- package/userProperty.js +22 -1
package/authenticator.js
CHANGED
|
@@ -16,29 +16,35 @@ definition.authenticator({
|
|
|
16
16
|
let userObserver = null
|
|
17
17
|
let oldCredentials = null
|
|
18
18
|
await authenticatedTable.object(session).onChange(async (authData, oldAuthData) => {
|
|
19
|
+
//output.debug("NEW USER AUTH", authData, "FROM", oldAuthData)
|
|
19
20
|
const newUser = authData ? authData.user : null
|
|
20
21
|
if(newUser == user) return
|
|
21
22
|
if(user) {
|
|
22
|
-
|
|
23
|
+
if(userObject) {
|
|
24
|
+
await userObject.unobserve(userObserver)
|
|
25
|
+
}
|
|
23
26
|
userObject = null
|
|
24
27
|
userObserver = null
|
|
25
28
|
}
|
|
26
|
-
if(
|
|
29
|
+
if(newUser) {
|
|
27
30
|
user = newUser
|
|
31
|
+
//output.debug("NEW USER", user)
|
|
28
32
|
userObject = userTable.object(user)
|
|
33
|
+
const currentUserObject = userObject
|
|
29
34
|
await userObject.onChange(async (userData, oldUserData) => {
|
|
30
35
|
const newCredentials = userData ? {
|
|
31
36
|
id: user,
|
|
32
37
|
user,
|
|
33
38
|
roles: userData.roles
|
|
34
39
|
} : null
|
|
40
|
+
//output.debug("NEW CREDENTIALS", newCredentials)
|
|
35
41
|
output.change(newCredentials, oldCredentials)
|
|
36
42
|
oldCredentials = newCredentials
|
|
37
43
|
}).then(observer => {
|
|
38
44
|
if(user == newUser) {
|
|
39
45
|
userObserver = observer
|
|
40
46
|
} else { // if user changed before observer loaded data
|
|
41
|
-
|
|
47
|
+
currentUserObject.unobserve(observer)
|
|
42
48
|
}
|
|
43
49
|
})
|
|
44
50
|
} else {
|
package/index.js
CHANGED
|
@@ -40,6 +40,8 @@ definition.trigger({
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
async execute({ user, session }, { client, service }, emit) {
|
|
43
|
+
const userData = await User.get(user)
|
|
44
|
+
if(!userData) throw 'userNotFound'
|
|
43
45
|
emit({
|
|
44
46
|
type: "signedIn",
|
|
45
47
|
user, session
|
|
@@ -49,16 +51,6 @@ definition.trigger({
|
|
|
49
51
|
|
|
50
52
|
definition.action({
|
|
51
53
|
name: 'signOut',
|
|
52
|
-
properties: {
|
|
53
|
-
user: {
|
|
54
|
-
type: User,
|
|
55
|
-
validation: ['nonEmpty']
|
|
56
|
-
},
|
|
57
|
-
session: {
|
|
58
|
-
type: Session,
|
|
59
|
-
validation: ['nonEmpty']
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
54
|
async execute({ }, { client, service }, emit) {
|
|
63
55
|
if(!client.user) throw "notSignedIn"
|
|
64
56
|
emit({
|
|
@@ -95,5 +87,25 @@ definition.trigger({
|
|
|
95
87
|
}
|
|
96
88
|
})
|
|
97
89
|
|
|
90
|
+
definition.action({
|
|
91
|
+
name: 'deleteMe',
|
|
92
|
+
properties: {
|
|
93
|
+
},
|
|
94
|
+
access: (params, { client }) => {
|
|
95
|
+
return !!client.user
|
|
96
|
+
},
|
|
97
|
+
async execute({ }, { client, service }, emit) {
|
|
98
|
+
const user = client.user
|
|
99
|
+
await service.trigger({
|
|
100
|
+
type: 'userDeleted',
|
|
101
|
+
user
|
|
102
|
+
})
|
|
103
|
+
emit([{
|
|
104
|
+
type: "deleted",
|
|
105
|
+
user
|
|
106
|
+
}])
|
|
107
|
+
return user
|
|
108
|
+
}
|
|
109
|
+
})
|
|
98
110
|
|
|
99
111
|
module.exports = definition
|
package/model.js
CHANGED
|
@@ -72,4 +72,17 @@ definition.event({
|
|
|
72
72
|
}
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
+
definition.event({
|
|
76
|
+
name: "deleted",
|
|
77
|
+
properties: {
|
|
78
|
+
user: {
|
|
79
|
+
type: User
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
async execute({ user }) {
|
|
83
|
+
const authenticated = await AuthenticatedUser.indexRangeGet('byUser', user)
|
|
84
|
+
await Promise.all([ User.delete(user) ].concat(authenticated.map(auth => AuthenticatedUser.delete(auth))))
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
75
88
|
module.exports = { User, AuthenticatedUser }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/user-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@live-change/framework": "^0.5.7",
|
|
25
25
|
"@live-change/relations-plugin": "^0.1.10"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "add122f25ae8a848c2d24e1a75c3c9ae69d86faa"
|
|
28
28
|
}
|
package/userItem.js
CHANGED
|
@@ -32,7 +32,10 @@ definition.processor(function(service, app) {
|
|
|
32
32
|
const viewName = 'myUser' + modelName + 's'
|
|
33
33
|
service.views[viewName] = new ViewDefinition({
|
|
34
34
|
name: viewName,
|
|
35
|
-
access
|
|
35
|
+
access(params, context) {
|
|
36
|
+
if(!context.client.user) return false
|
|
37
|
+
return config.userReadAccess ? config.userReadAccess(params, context) : true
|
|
38
|
+
},
|
|
36
39
|
properties: App.rangeProperties,
|
|
37
40
|
daoPath(range, { client, context }) {
|
|
38
41
|
const path = modelRuntime().indexRangePath('byUser', [client.user], range )
|
|
@@ -44,7 +47,10 @@ definition.processor(function(service, app) {
|
|
|
44
47
|
const viewName = 'myUser' + modelName + 'sBy' + sortFieldUc
|
|
45
48
|
service.views[viewName] = new ViewDefinition({
|
|
46
49
|
name: viewName,
|
|
47
|
-
access
|
|
50
|
+
access(params, context) {
|
|
51
|
+
if(!context.client.user) return false
|
|
52
|
+
return config.userReadAccess ? config.userReadAccess(params, context) : true
|
|
53
|
+
},
|
|
48
54
|
properties: App.rangeProperties,
|
|
49
55
|
daoPath(range, { client, context }) {
|
|
50
56
|
return modelRuntime().sortedIndexRangePath('byUser' + sortFieldUc, [client.user], range )
|
package/userProperty.js
CHANGED
|
@@ -32,13 +32,34 @@ definition.processor(function(service, app) {
|
|
|
32
32
|
const viewName = 'myUser' + modelName
|
|
33
33
|
service.views[viewName] = new ViewDefinition({
|
|
34
34
|
name: viewName,
|
|
35
|
-
access
|
|
35
|
+
access(params, context) {
|
|
36
|
+
if(!context.client.user) return false
|
|
37
|
+
return config.userReadAccess ? config.userReadAccess(params, context) : true
|
|
38
|
+
},
|
|
36
39
|
daoPath(params, { client, context }) {
|
|
37
40
|
return modelRuntime().path(client.user)
|
|
38
41
|
}
|
|
39
42
|
})
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
if(config.userViews) {
|
|
46
|
+
for(const view of config.userViews) {
|
|
47
|
+
const viewName = view.name || ('myUser' + (view.prefix || '') + modelName + (view.suffix || ''))
|
|
48
|
+
service.views[viewName] = new ViewDefinition({
|
|
49
|
+
name: viewName,
|
|
50
|
+
access(params, context) {
|
|
51
|
+
if(!context.client.user) return false
|
|
52
|
+
return view.access ? view.access(params, context) : true
|
|
53
|
+
},
|
|
54
|
+
daoPath(params, { client, context }) {
|
|
55
|
+
return view.fields
|
|
56
|
+
? modelRuntime().limitedPath(client.user, view.fields)
|
|
57
|
+
: modelRuntime().path(client.user)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
42
63
|
if(config.userSetAccess || config.userWriteAccess) {
|
|
43
64
|
const eventName = 'userOwned' + modelName + 'Set'
|
|
44
65
|
const actionName = 'setMyUser' + modelName
|