Is it necessary to return
when you hand over to the next callback? So in the example given here :
function (user, context, callback) {
let authMethods = [];
if (context.authentication && Array.isArray(context.authentication.methods)) {
authMethods = context.authentication.methods;
}
const completedMfa = !!authMethods.find((method) => method.name === 'mfa');
if (completedMfa) {
return callback(null, user, context);
}
context.multifactor = {
provider: 'any',
allowRememberBrowser: false
};
callback(null, user, context);
}
The first call to callback(null, user, context)
is return
-ed, but the second isn’t. Is there any reason for this, or is it just used to avoid executing the rest of the rule? Is there any use of that returned value that we should be aware of?
tyf
July 27, 2022, 12:04am
4
Hello @sean.mclemon1 welcome to the community!
sean.mclemon1:
The first call to callback(null, user, context)
is return
-ed, but the second isn’t. Is there any reason for this, or is it just used to avoid executing the rest of the rule? Is there any use of that returned value that we should be aware of?
Good question! It looks to me like it is used to just stop execution, here’s another rule for example:
* For example, you can save it under `app_metadata.social_email`.
*
* @title Get email address from Twitter
* @overview Get user email address from Twitter.
* @gallery true
* @category enrich profile
*/
function getTwitterEmail(user, context, callback) {
// additional request below is specific to Twitter
if (context.connectionStrategy !== 'twitter') {
return callback(null, user, context);
}
const _ = require('lodash');
const request = require('request');
const oauth = require('oauth-sign');
const uuid = require('uuid');
const url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
const consumerKey = configuration.TWITTER_CONSUMER_KEY;
1 Like
tyf
Closed
August 11, 2022, 12:04am
5
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.