Mahdi Jafari
Mahdi Jafari

Reputation: 415

Migrating from Hooks for Actions does not work. How to fix it?

I have a Pre User Registration hook that sets a custom field is_approved to user. and this is the code:

module.exports = function (user, context, cb) {
  var response = {};

  response.user = user;

  // Add user or app metadata to the newly created user
  // Adding is_approved attribute to app_metadata and setting it to false
  response.user.app_metadata = { is_approved: false };

  // Continue with the response
  cb(null, response);
};

Since hooks are going to be deprecated, I want to create use actions. So I created this action:

exports.onExecutePreUserRegistration = async (event, api) => {
    api.user.setAppMetadata('is_approved', false)
};

This should add is_approved field to app metadata in username/password logins, but it does not add. In addition, I added another Action to add this field in social logins:

exports.onExecutePostLogin = async (event, api) => {
    if (event.stats.logins_count == 1) {
      api.user.setAppMetadata('is_approved', false)
    }
};

I deployed the actions and disabled the hook. I registered a user but the app metadata is empty which means that these actions are not working.

Upvotes: 1

Views: 118

Answers (0)

Related Questions