backend-manager 2.2.2 → 2.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -66,4 +66,4 @@
66
66
  "src/",
67
67
  "templates/"
68
68
  ]
69
- }
69
+ }
@@ -12,13 +12,37 @@ Module.prototype.main = function () {
12
12
  return new Promise(async function(resolve, reject) {
13
13
 
14
14
  const fetch = Manager.require('wonderful-fetch');
15
+ const _ = Manager.require('lodash');
15
16
 
16
- const uid = payload.data.payload.uid;
17
+ let uid = payload.data.payload.uid;
17
18
  const app = payload.data.payload.appId || payload.data.payload.app || Manager.config.app.id;
18
19
 
19
20
  let uuid = null;
20
21
  let error;
21
22
 
23
+ let customToken = null;
24
+
25
+ if (payload.data.authenticationToken || payload.data.backendManagerKey) {
26
+ await self.Api.resolveUser({adminRequired: true})
27
+ .then(async (user) => {
28
+ uid = _.get(user, 'auth.uid', null);
29
+ await self.libraries.admin.auth().createCustomToken(uid)
30
+ .then(token => {
31
+ customToken = token;
32
+ })
33
+ .catch(e => {
34
+ error = assistant.errorManager(`Failed to create custom token: ${e}`, {code: 500, sentry: false, send: false, log: false}).error
35
+ })
36
+ })
37
+ .catch(e => {
38
+ assistant.errorManager(`Failed to resolve user: ${e}`, {code: 500, sentry: false, send: false, log: true})
39
+ })
40
+
41
+ if (error) {
42
+ return reject(error)
43
+ }
44
+ }
45
+
22
46
  // Generate uuid
23
47
  if (uid) {
24
48
  await Api.import('general:generate-uuid', {version: 5, name: uid})
@@ -52,6 +76,7 @@ Module.prototype.main = function () {
52
76
  return resolve({
53
77
  data: {
54
78
  uuid: uuid,
79
+ customToken: customToken,
55
80
  timestamp: new Date().toISOString(),
56
81
  ip: assistant.request.ip,
57
82
  country: assistant.request.country,
@@ -60,9 +85,12 @@ Module.prototype.main = function () {
60
85
  });
61
86
  })
62
87
  .catch(e => {
63
- return reject(new Error(`Error fetching app details: ${e}`))
88
+ return reject(assistant.errorManager(`Error fetching app details: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
64
89
  })
65
90
 
91
+
92
+
93
+
66
94
  });
67
95
 
68
96
  };