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

**URL:** <https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564>\
**Category:** Get Help\
**Tags:** automatic-migration, user-management\
**Created:** [September 19, 2023, 10:03am UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564 "2023-09-19T10:03:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahdi1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mahdi1/32/50485_2.png) [@mahdi1](https://community.auth0.com/u/mahdi1)\
**Post date:** [September 19, 2023, 10:03am UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/1 "2023-09-19T10:03:31Z")

</div>

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

```javascript
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:

```javascript
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:

```javascript
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.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 19, 2023, 9:18pm UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/3 "2023-09-19T21:18:04Z")

</div>

Hey there @mahdi1 welcome to the community!

> [@mahdi1](#):
>
> ```auto
> exports.onExecutePreUserRegistration = async (event, api) => {
> api.user.setAppMetadata('is_approved', false)
> };
> 
> ```

This code should work - Do you have any hooks or rules enabled that could be interfering? I would double check to see if you have any enabled, and if you do remove them and test again.

Keep us posted!

---

<div class="post-metadata">

**Author:** ![mahdi1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mahdi1/32/50485_2.png) [@mahdi1](https://community.auth0.com/u/mahdi1)\
**Post date:** [September 20, 2023, 3:27am UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/4 "2023-09-20T03:27:54Z")

</div>

Hey @ty.frith. Thanks for answering. I have one hook and two rules. I disabled all of them and registered a user. But still nothing. Could you please help?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/e/6/e63fddcccd17fbd1fe0cc151a50d318d881b9552.png)

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 20, 2023, 9:58pm UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/5 "2023-09-20T21:58:21Z")

</div>

I’m having a hard time coming up with anything else to check - Is the user you are registering a Auth0 database user or social (google, facebook, etc.), passwordless, etc.?

---

<div class="post-metadata">

**Author:** ![mahdi1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mahdi1/32/50485_2.png) [@mahdi1](https://community.auth0.com/u/mahdi1)\
**Post date:** [September 21, 2023, 2:44am UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/6 "2023-09-21T02:44:53Z")

</div>

Thanks for your reply @ty.frith. I registered the user with Google (social login).

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 21, 2023, 7:15pm UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/7 "2023-09-21T19:15:54Z")

</div>

Hey @mahdi1 no problem, happy to help where I can!

> [@mahdi1](#):
>
> I registered the user with Google (social login).

Thanks for confirming - Only the Post Login Action will run on Social logins. The Post Login Action code you shared above seems to be working in my environment when logging in for the first time with a Google user:

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

```

 ![Screenshot 2023-09-21 at 12.16.13 PM](https://global.discourse-cdn.com/auth0/original/3X/d/1/d17761f36cb6f166f5511e9c523408f191d162b8.png)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 5, 2023, 7:16pm UTC](https://community.auth0.com/t/migrating-from-hooks-for-actions-does-not-work-how-to-fix-it/116564/8 "2023-10-05T19:16:15Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
