backend-manager 3.2.33 → 3.2.34
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/manager/functions/core/events/auth/before-create.js +5 -6
- package/src/manager/functions/core/events/auth/before-signin.js +3 -4
- package/src/manager/functions/core/events/auth/on-create.js +11 -11
- package/src/manager/functions/core/events/auth/on-delete.js +8 -6
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@ function Module() {
|
|
|
9
9
|
Module.prototype.init = function (Manager, payload) {
|
|
10
10
|
const self = this;
|
|
11
11
|
self.Manager = Manager;
|
|
12
|
-
self.libraries = Manager.libraries;
|
|
13
12
|
self.assistant = Manager.Assistant();
|
|
13
|
+
self.libraries = Manager.libraries;
|
|
14
14
|
self.user = payload.user;
|
|
15
15
|
self.context = payload.context;
|
|
16
16
|
|
|
@@ -19,15 +19,14 @@ Module.prototype.init = function (Manager, payload) {
|
|
|
19
19
|
|
|
20
20
|
Module.prototype.main = function () {
|
|
21
21
|
const self = this;
|
|
22
|
-
const
|
|
22
|
+
const Manager = self.Manager;
|
|
23
23
|
const assistant = self.assistant;
|
|
24
24
|
const user = self.user;
|
|
25
25
|
const context = self.context;
|
|
26
26
|
|
|
27
27
|
return new Promise(async function(resolve, reject) {
|
|
28
|
-
const functions = self.libraries
|
|
29
|
-
const
|
|
30
|
-
const storage = self.Manager.storage({ temporary: true, name: 'rate-limiting' });
|
|
28
|
+
const { admin, functions } = self.libraries;
|
|
29
|
+
const storage = Manager.storage({ temporary: true, name: 'rate-limiting' });
|
|
31
30
|
|
|
32
31
|
assistant.log(`Request: ${user.uid}`, user, context);
|
|
33
32
|
|
|
@@ -90,7 +89,7 @@ Module.prototype.main = function () {
|
|
|
90
89
|
// If it exists, just add the activity data
|
|
91
90
|
if (!get(existingAccount, 'auth.uid', null) || !get(existingAccount, 'auth.email', null)) {
|
|
92
91
|
account = merge(
|
|
93
|
-
|
|
92
|
+
Manager.User({
|
|
94
93
|
auth: {
|
|
95
94
|
uid: user.uid,
|
|
96
95
|
email: user.email,
|
|
@@ -7,8 +7,8 @@ function Module() {
|
|
|
7
7
|
Module.prototype.init = function (Manager, payload) {
|
|
8
8
|
const self = this;
|
|
9
9
|
self.Manager = Manager;
|
|
10
|
-
self.libraries = Manager.libraries;
|
|
11
10
|
self.assistant = Manager.Assistant();
|
|
11
|
+
self.libraries = Manager.libraries;
|
|
12
12
|
self.user = payload.user
|
|
13
13
|
self.context = payload.context
|
|
14
14
|
|
|
@@ -17,14 +17,13 @@ Module.prototype.init = function (Manager, payload) {
|
|
|
17
17
|
|
|
18
18
|
Module.prototype.main = function () {
|
|
19
19
|
const self = this;
|
|
20
|
-
const
|
|
20
|
+
const Manager = self.Manager;
|
|
21
21
|
const assistant = self.assistant;
|
|
22
22
|
const user = self.user;
|
|
23
23
|
const context = self.context;
|
|
24
24
|
|
|
25
25
|
return new Promise(async function(resolve, reject) {
|
|
26
|
-
const functions = self.libraries
|
|
27
|
-
const admin = self.libraries.admin;
|
|
26
|
+
const { admin, functions } = self.libraries;
|
|
28
27
|
|
|
29
28
|
assistant.log(`Request: ${user.uid}`, user, context);
|
|
30
29
|
|
|
@@ -11,8 +11,8 @@ function Module() {
|
|
|
11
11
|
Module.prototype.init = function (Manager, payload) {
|
|
12
12
|
const self = this;
|
|
13
13
|
self.Manager = Manager;
|
|
14
|
-
self.libraries = Manager.libraries;
|
|
15
14
|
self.assistant = Manager.Assistant();
|
|
15
|
+
self.libraries = Manager.libraries;
|
|
16
16
|
self.user = payload.user
|
|
17
17
|
self.context = payload.context
|
|
18
18
|
|
|
@@ -21,12 +21,14 @@ Module.prototype.init = function (Manager, payload) {
|
|
|
21
21
|
|
|
22
22
|
Module.prototype.main = function () {
|
|
23
23
|
const self = this;
|
|
24
|
-
const
|
|
24
|
+
const Manager = self.Manager;
|
|
25
25
|
const assistant = self.assistant;
|
|
26
26
|
const user = self.user;
|
|
27
27
|
const context = self.context;
|
|
28
28
|
|
|
29
29
|
return new Promise(async function(resolve, reject) {
|
|
30
|
+
const { admin, functions } = self.libraries;
|
|
31
|
+
|
|
30
32
|
// ⛔️⛔️⛔️ This function could be triggered when the user signs up with Google after already having a email/password account
|
|
31
33
|
|
|
32
34
|
assistant.log(`Request: ${user.uid}`, user, context);
|
|
@@ -45,7 +47,7 @@ Module.prototype.main = function () {
|
|
|
45
47
|
// Check if exists already
|
|
46
48
|
let existingUser;
|
|
47
49
|
await powertools.poll(async () => {
|
|
48
|
-
existingUser = await
|
|
50
|
+
existingUser = await admin.firestore().doc(`users/${user.uid}`)
|
|
49
51
|
.get()
|
|
50
52
|
.then((doc) => doc.data())
|
|
51
53
|
.catch(e => e);
|
|
@@ -66,7 +68,7 @@ Module.prototype.main = function () {
|
|
|
66
68
|
assistant.log(`Result of existing user ${user.uid} search (age=${ageInSeconds}):`, existingUser);
|
|
67
69
|
|
|
68
70
|
// Build user object
|
|
69
|
-
let userRecord =
|
|
71
|
+
let userRecord = Manager.User().properties;
|
|
70
72
|
|
|
71
73
|
userRecord = merge(userRecord, existingUser, {
|
|
72
74
|
auth: {
|
|
@@ -100,7 +102,7 @@ Module.prototype.main = function () {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// Set up analytics
|
|
103
|
-
const analytics =
|
|
105
|
+
const analytics = Manager.Analytics({
|
|
104
106
|
assistant: assistant,
|
|
105
107
|
uuid: userRecord.auth.uid,
|
|
106
108
|
})
|
|
@@ -123,13 +125,13 @@ Module.prototype.main = function () {
|
|
|
123
125
|
await self.incrementUserCount().catch(e => e);
|
|
124
126
|
|
|
125
127
|
// Add metadata
|
|
126
|
-
userRecord.metadata =
|
|
128
|
+
userRecord.metadata = Manager.Metadata().set({tag: 'auth:on-create'});
|
|
127
129
|
|
|
128
130
|
// Log
|
|
129
131
|
assistant.log(`main(): User record created ${userRecord.auth.uid}:`, userRecord);
|
|
130
132
|
|
|
131
133
|
// Add user record
|
|
132
|
-
await
|
|
134
|
+
await admin.firestore().doc(`users/${userRecord.auth.uid}`)
|
|
133
135
|
.set(userRecord, {merge: true})
|
|
134
136
|
.catch((e) => {
|
|
135
137
|
assistant.error(`Failed save user record`, e);
|
|
@@ -157,7 +159,6 @@ Module.prototype.deleteUser = function (user) {
|
|
|
157
159
|
|
|
158
160
|
return new Promise(async function(resolve, reject) {
|
|
159
161
|
const Manager = self.Manager;
|
|
160
|
-
const libraries = self.libraries;
|
|
161
162
|
const assistant = self.assistant;
|
|
162
163
|
|
|
163
164
|
// Log
|
|
@@ -195,10 +196,9 @@ Module.prototype.incrementUserCount = function () {
|
|
|
195
196
|
const self = this;
|
|
196
197
|
|
|
197
198
|
return new Promise(async function(resolve, reject) {
|
|
198
|
-
const libraries = self.libraries;
|
|
199
|
-
const assistant = self.assistant;
|
|
200
199
|
const Manager = self.Manager;
|
|
201
|
-
const
|
|
200
|
+
const assistant = self.assistant;
|
|
201
|
+
const { admin } = self.libraries;
|
|
202
202
|
|
|
203
203
|
// Log
|
|
204
204
|
assistant.log(`incrementUserCount(): Starting...`);
|
|
@@ -7,8 +7,8 @@ function Module() {
|
|
|
7
7
|
Module.prototype.init = function (Manager, payload) {
|
|
8
8
|
const self = this;
|
|
9
9
|
self.Manager = Manager;
|
|
10
|
-
self.libraries = Manager.libraries;
|
|
11
10
|
self.assistant = Manager.Assistant();
|
|
11
|
+
self.libraries = Manager.libraries;
|
|
12
12
|
self.user = payload.user
|
|
13
13
|
self.context = payload.context
|
|
14
14
|
|
|
@@ -17,16 +17,18 @@ Module.prototype.init = function (Manager, payload) {
|
|
|
17
17
|
|
|
18
18
|
Module.prototype.main = function () {
|
|
19
19
|
const self = this;
|
|
20
|
-
const
|
|
20
|
+
const Manager = self.Manager;
|
|
21
21
|
const assistant = self.assistant;
|
|
22
22
|
const user = self.user;
|
|
23
23
|
const context = self.context;
|
|
24
24
|
|
|
25
25
|
return new Promise(async function(resolve, reject) {
|
|
26
|
+
const { admin, functions } = self.libraries;
|
|
27
|
+
|
|
26
28
|
assistant.log(`Request: ${user.uid}`, user, context);
|
|
27
29
|
|
|
28
30
|
// Set up analytics
|
|
29
|
-
const analytics =
|
|
31
|
+
const analytics = Manager.Analytics({
|
|
30
32
|
assistant: assistant,
|
|
31
33
|
uuid: user.uid,
|
|
32
34
|
})
|
|
@@ -38,7 +40,7 @@ Module.prototype.main = function () {
|
|
|
38
40
|
|
|
39
41
|
// Delete user record
|
|
40
42
|
assistant.log(`Delete user record...`);
|
|
41
|
-
await
|
|
43
|
+
await admin.firestore().doc(`users/${user.uid}`)
|
|
42
44
|
.delete()
|
|
43
45
|
.then((r) => {
|
|
44
46
|
assistant.log(`Delete user record success`);
|
|
@@ -49,9 +51,9 @@ Module.prototype.main = function () {
|
|
|
49
51
|
|
|
50
52
|
// Update user count
|
|
51
53
|
assistant.log(`Decrement user count...`);
|
|
52
|
-
await
|
|
54
|
+
await admin.firestore().doc(`meta/stats`)
|
|
53
55
|
.update({
|
|
54
|
-
'users.total':
|
|
56
|
+
'users.total': admin.firestore.FieldValue.increment(-1),
|
|
55
57
|
})
|
|
56
58
|
.then((r) => {
|
|
57
59
|
assistant.log(`Decrement user count success`);
|