backend-manager 3.2.33 → 3.2.35
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 +12 -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
|
|
|
@@ -2,6 +2,7 @@ const { get, merge } = require('lodash');
|
|
|
2
2
|
const powertools = require('node-powertools');
|
|
3
3
|
const fetch = require('wonderful-fetch');
|
|
4
4
|
|
|
5
|
+
const MAX_SIGNUPS = 3;
|
|
5
6
|
const MAX_AGE = 30;
|
|
6
7
|
|
|
7
8
|
function Module() {
|
|
@@ -11,8 +12,8 @@ function Module() {
|
|
|
11
12
|
Module.prototype.init = function (Manager, payload) {
|
|
12
13
|
const self = this;
|
|
13
14
|
self.Manager = Manager;
|
|
14
|
-
self.libraries = Manager.libraries;
|
|
15
15
|
self.assistant = Manager.Assistant();
|
|
16
|
+
self.libraries = Manager.libraries;
|
|
16
17
|
self.user = payload.user
|
|
17
18
|
self.context = payload.context
|
|
18
19
|
|
|
@@ -21,12 +22,14 @@ Module.prototype.init = function (Manager, payload) {
|
|
|
21
22
|
|
|
22
23
|
Module.prototype.main = function () {
|
|
23
24
|
const self = this;
|
|
24
|
-
const
|
|
25
|
+
const Manager = self.Manager;
|
|
25
26
|
const assistant = self.assistant;
|
|
26
27
|
const user = self.user;
|
|
27
28
|
const context = self.context;
|
|
28
29
|
|
|
29
30
|
return new Promise(async function(resolve, reject) {
|
|
31
|
+
const { admin, functions } = self.libraries;
|
|
32
|
+
|
|
30
33
|
// ⛔️⛔️⛔️ This function could be triggered when the user signs up with Google after already having a email/password account
|
|
31
34
|
|
|
32
35
|
assistant.log(`Request: ${user.uid}`, user, context);
|
|
@@ -45,7 +48,7 @@ Module.prototype.main = function () {
|
|
|
45
48
|
// Check if exists already
|
|
46
49
|
let existingUser;
|
|
47
50
|
await powertools.poll(async () => {
|
|
48
|
-
existingUser = await
|
|
51
|
+
existingUser = await admin.firestore().doc(`users/${user.uid}`)
|
|
49
52
|
.get()
|
|
50
53
|
.then((doc) => doc.data())
|
|
51
54
|
.catch(e => e);
|
|
@@ -66,7 +69,7 @@ Module.prototype.main = function () {
|
|
|
66
69
|
assistant.log(`Result of existing user ${user.uid} search (age=${ageInSeconds}):`, existingUser);
|
|
67
70
|
|
|
68
71
|
// Build user object
|
|
69
|
-
let userRecord =
|
|
72
|
+
let userRecord = Manager.User().properties;
|
|
70
73
|
|
|
71
74
|
userRecord = merge(userRecord, existingUser, {
|
|
72
75
|
auth: {
|
|
@@ -100,7 +103,7 @@ Module.prototype.main = function () {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
// Set up analytics
|
|
103
|
-
const analytics =
|
|
106
|
+
const analytics = Manager.Analytics({
|
|
104
107
|
assistant: assistant,
|
|
105
108
|
uuid: userRecord.auth.uid,
|
|
106
109
|
})
|
|
@@ -123,13 +126,13 @@ Module.prototype.main = function () {
|
|
|
123
126
|
await self.incrementUserCount().catch(e => e);
|
|
124
127
|
|
|
125
128
|
// Add metadata
|
|
126
|
-
userRecord.metadata =
|
|
129
|
+
userRecord.metadata = Manager.Metadata().set({tag: 'auth:on-create'});
|
|
127
130
|
|
|
128
131
|
// Log
|
|
129
132
|
assistant.log(`main(): User record created ${userRecord.auth.uid}:`, userRecord);
|
|
130
133
|
|
|
131
134
|
// Add user record
|
|
132
|
-
await
|
|
135
|
+
await admin.firestore().doc(`users/${userRecord.auth.uid}`)
|
|
133
136
|
.set(userRecord, {merge: true})
|
|
134
137
|
.catch((e) => {
|
|
135
138
|
assistant.error(`Failed save user record`, e);
|
|
@@ -157,7 +160,6 @@ Module.prototype.deleteUser = function (user) {
|
|
|
157
160
|
|
|
158
161
|
return new Promise(async function(resolve, reject) {
|
|
159
162
|
const Manager = self.Manager;
|
|
160
|
-
const libraries = self.libraries;
|
|
161
163
|
const assistant = self.assistant;
|
|
162
164
|
|
|
163
165
|
// Log
|
|
@@ -195,10 +197,9 @@ Module.prototype.incrementUserCount = function () {
|
|
|
195
197
|
const self = this;
|
|
196
198
|
|
|
197
199
|
return new Promise(async function(resolve, reject) {
|
|
198
|
-
const libraries = self.libraries;
|
|
199
|
-
const assistant = self.assistant;
|
|
200
200
|
const Manager = self.Manager;
|
|
201
|
-
const
|
|
201
|
+
const assistant = self.assistant;
|
|
202
|
+
const { admin } = self.libraries;
|
|
202
203
|
|
|
203
204
|
// Log
|
|
204
205
|
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`);
|