当我尝试为用户设置自定义声明时,我无法部署云功能。这是函数
exports.verifyPhone = functions.https.onRequest(async (request, response) => {
const db = admin.firestore();
const userId = request.body['userId'];
const firebaseId = request.body['firebaseId'];
const now = Date.now();
const userRef = db.collection('users').doc(userId);
const updateResult = await userRef.update({
phoneVerified: true
});
const x = await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});
console.log('folder set');
if (Number(updateResult.writeTime) > now) {
return response.json({
status: 1,
message: 'Phone verified successfully',
result: null
});
} else {
return response.json({
status: 0,
message: 'An error occurred, please try again later',
result: null
});
}
});
但如果该行
const x = await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});
被评论,该功能将成功部署,我已将firebase-admin导入为
import * as admin from 'firebase-admin';
这就是日志
0 info it worked if it ends with ok
1 verbose cli [ '/home/me/.nvm/versions/node/v9.5.0/bin/node',
1 verbose cli '/home/me/.nvm/versions/node/v9.5.0/bin/npm',
1 verbose cli '--prefix',
1 verbose cli '/home/me/Documents/TfmFirebase/functions',
1 verbose cli 'run',
1 verbose cli 'lint' ]
2 info using npm@5.6.0
3 info using node@v9.5.0
4 verbose run-script [ 'prelint', 'lint', 'postlint' ]
5 info lifecycle functions@~prelint: functions@
6 info lifecycle functions@~lint: functions@
7 verbose lifecycle functions@~lint: unsafe-perm in lifecycle true
8 verbose lifecycle functions@~lint: PATH: /home/me/.nvm/versions/node/v9.5.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/me/Documents/TfmFireba$
9 verbose lifecycle functions@~lint: CWD: /home/me/Documents/TfmFirebase/functions
10 silly lifecycle functions@~lint: Args: [ '-c', 'tslint -p tslint.json' ]
11 silly lifecycle functions@~lint: Returned: code: 2 signal: null
12 info lifecycle functions@~lint: Failed to exec lint script
13 verbose stack Error: functions@ lint: `tslint -p tslint.json`
13 verbose stack Exit status 2
13 verbose stack at EventEmitter.<anonymous> (/home/me/.nvm/versions/node/v9.5.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack at EventEmitter.emit (events.js:160:13)
13 verbose stack at ChildProcess.<anonymous> (/home/me/.nvm/versions/node/v9.5.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:160:13)
13 verbose stack at maybeClose (internal/child_process.js:943:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid functions@
15 verbose cwd /home/me/Documents/TfmFirebase
16 verbose Linux 4.13.0-37-generic
17 verbose argv "/home/me/.nvm/versions/node/v9.5.0/bin/node" "/home/me/.nvm/versions/node/v9.5.0/bin/npm" "--prefix" "/home/me/Documents/TfmFirebase/functions" "run" $
18 verbose node v9.5.0
19 verbose npm v5.6.0
20 error code ELIFECYCLE
21 error errno 2
22 error functions@ lint: `tslint -p tslint.json`
22 error Exit status 2
23 error Failed at the functions@ lint script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]
我无法弄清楚出了什么问题。任何人都可以告诉代码有什么问题吗?
答案 0 :(得分:6)
如果您查看正常输出(此处未显示),而不是详细日志(您正在显示),问题就很明显了。这就是tslint告诉你该怎么做的地方:
Expression has type `void`. Put it on its own line as a statement.
setCustomUserClaims()会返回包含void
的承诺。换句话说,它不会为调用者生成任何数据。 TypeScript告诉你,将void
分配给x
是没有意义的,你根本不应该分配任何东西:
await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});
console.log('folder set');