has2faEnabled Callback Argument?

The Meteor docs for has2faEnabled say:

callback Function

Called with a boolean on success that indicates whether the user has or not 2FA enabled, or with a single Error argument on failure.

I tried it like this, with a single argument for the callback:

useEffect(() => {
    Accounts.has2faEnabled((result) => {
        debugger; // <== check callback argument here
        if (result) {
            setHasAlreadyEnabled2FA(true);
        } else {
            setHasAlreadyEnabled2FA(false);
        }
    })
}, []);

…and when there is no error, the result argument comes back undefined – it does not report true or false.

I was expecting a boolean in the case of no error. What super-obvious thing am I missing?

// My bad. @coagmano fixed it.

1 Like

@minhna looks like on the client this doesn’t return a value:

Looking at that code, it’s calling a Meteor method, so the signature of the callback is a node-style error first callback:

    Accounts.has2faEnabled((error, result) => {

where the error is always the first arg (null if no error) and the result the second

The docs for this could definitely be clearer

2 Likes

You’re right. @vikr00001 got undefined because it’s error param. not the result one.