2

I am not able to deploy cloud function, when I try to set custom claim on a user. This is the function

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
        });
    }

});

but if the line

const x = await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});

is commented, the function will deploy successfully, I have imported firebase-admin as

import * as admin from 'firebase-admin';

and this the log

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 [email protected]
3 info using [email protected]
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 ]

I am not able to figure out what is wrong. Can anyone tell what is wrong with the code?

1 Answer 1

6

The problem is evident if you look at the normal output (which you're not showing here), rather than the verbose log (which you are showing). That's where tslint is telling you what to do:

Expression has type `void`. Put it on its own line as a statement.

setCustomUserClaims() returns a promise that contains void. In other words, it doesn't generate any data for the caller to consume. TypeScript is telling you that assigning that void to x is meaningless, and you should just not assign anything at all:

await admin.auth().setCustomUserClaims(firebaseId,{folder:userId});
console.log('folder set');
Sign up to request clarification or add additional context in comments.

1 Comment

I found that a couple of minutes before and i removed the const x = and simply await for the call to finish. Thanks for your time and can you have a look at this question regarding the security rules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.