【问题标题】:Cannot deploy function to Firebase无法将功能部署到 Firebase
【发布时间】:2018-04-01 16:09:39
【问题描述】:

当我尝试对用户设置自定义声明时,我无法部署云功能。这是函数

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 ]

我无法弄清楚出了什么问题。谁能告诉代码有什么问题?

【问题讨论】:

    标签: typescript firebase google-cloud-functions firebase-admin


    【解决方案1】:

    如果您查看正常输出(此处未显示)而不是详细日志(您正在显示),则问题很明显。这就是 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');
    

    【讨论】:

    • 我发现几分钟前我删除了const x = 和简单的await 以完成通话。感谢您抽出宝贵时间,您能否就安全规则联系look at this question
    猜你喜欢
    • 1970-01-01
    • 2018-07-24
    • 2017-11-15
    • 1970-01-01
    • 2021-10-10
    • 2021-11-17
    • 2022-01-23
    • 2021-03-27
    相关资源
    最近更新 更多