backend-assistant
Advanced tools
Comparing version 0.0.67 to 0.0.68
{ | ||
"name": "backend-assistant", | ||
"version": "0.0.67", | ||
"version": "0.0.68", | ||
"description": "Powerful assistive functions for Firebase backends", | ||
@@ -30,4 +30,5 @@ "main": "src/index.js", | ||
"lodash": "^4.17.21", | ||
"resolve-account": "^0.0.1", | ||
"uuid": "^8.3.2" | ||
} | ||
} |
@@ -57,3 +57,3 @@ const os = require('os'); | ||
this.request.path = (this.ref.req.path || ''); | ||
this.request.user = require('./user.js')(); | ||
this.request.user = resolveAccount(); | ||
if (options.accept === 'json') { | ||
@@ -203,4 +203,13 @@ this.request.body = tryParse(this.ref.req.body || '{}'); | ||
options = options || {}; | ||
options.resolve = typeof options.resolve === 'undefined' ? true : options.resolve; | ||
const logOptions = {environment: options.log ? 'production' : 'development'} | ||
function _resolve(user) { | ||
if (options.resolve) { | ||
return resolveAccount(user) | ||
} else { | ||
return user; | ||
} | ||
} | ||
if (req.headers && req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) { | ||
@@ -231,3 +240,3 @@ // Read the ID Token from the Authorization header. | ||
self.request.user.roles.admin = true; | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} | ||
@@ -237,3 +246,3 @@ } else if (options.apiKey) { | ||
if (options.apiKey.includes('test')) { | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} | ||
@@ -252,3 +261,3 @@ await admin.firestore().collection(`users`) | ||
}); | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} else { | ||
@@ -260,3 +269,3 @@ self.log('No Firebase ID token was able to be extracted.', | ||
'or by passing backendManagerKey or authenticationToken in the body or query', logOptions); | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} | ||
@@ -283,6 +292,6 @@ | ||
}) | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} catch (error) { | ||
self.error('Error while verifying Firebase ID token:', error, logOptions); | ||
return self.request.user; | ||
return _resolve(self.request.user); | ||
} | ||
@@ -505,2 +514,7 @@ }; | ||
function resolveAccount(user) { | ||
const ResolveAccount = new (require('resolve-account'))(); | ||
return ResolveAccount.resolve(undefined, user) | ||
} | ||
module.exports = BackendAssistant; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22721
463
6
+ Addedresolve-account@^0.0.1
+ Addedresolve-account@0.0.1(transitive)