# Pre-user registration hook doesn't merge app\_metadata

**URL:** <https://community.auth0.com/t/pre-user-registration-hook-doesnt-merge-app-metadata/10585>\
**Category:** Get Help\
**Tags:** hooks\
**Created:** [April 3, 2018, 11:04am UTC](https://community.auth0.com/t/pre-user-registration-hook-doesnt-merge-app-metadata/10585 "2018-04-03T11:04:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewneil](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@drewneil](https://community.auth0.com/u/drewneil)\
**Post date:** [April 3, 2018, 11:04am UTC](https://community.auth0.com/t/pre-user-registration-hook-doesnt-merge-app-metadata/10585/1 "2018-04-03T11:04:12Z")

</div>

I believe that I’ve discovered a bug in the Pre-user registration hook. Here are detailed instructions on how to reproduce the bug.

## Test case

For testing purposes, I’m using this code with a Pre-user registration hook:

```javascript
module.exports = function (user, context, cb) {
  var response = {};
  response.user = user || {};
  response.user.user_metadata = user.user_metadata || {};
  response.user.app_metadata = user.app_metadata || {};

  response.user.user_metadata["email"] = user.email;
  response.user.app_metadata["email"] = user.email;

  cb(null, response);
};

```

## Testing using the webtask runner

I created a Pre-user registration hook using the Dashboard. I used the integrated runner to test using this body:

```json
{
  "user": {
    "email": "user1@foo.com",
    "user_metadata": {
      "hobby": "surfing"
    },
    "app_metadata": {
      "plan": "full"
    }
  },
  "context": {
    "connection": {}
  }
}

```

The response came back looking like this:

```json
{
  "user": {
    "email": "user1@foo.com",
    "user_metadata": {
      "hobby": "surfing",
      "email": "user1@foo.com"
    },
    "app_metadata": {
      "plan": "full",
      "email": "user1@foo.com"
    }
  }
}

```

As expected, the `email` field is merged into the `user_metadata` and `app_metadata` objects, while the pre-existing `hobby` and `plan` fields are preserved.

## Testing by posting to Management API

### Create a basic user (no metadata specified)

Post to [`/users`](https://auth0.com/docs/api/management/v2#!/Users/post_users) with the following data:

```json
{
  "connection": "Username-Password-Authentication",
  "email": "demo1@example.com",
  "password": "xX1234Xx",
}

```

Here’s the response (abridged to show relevant fields only):

```json
{
  "email": "demo1@example.com",
  "email_verified": false,
  "app_metadata": {
    "email": "demo1@example.com"
  },
  "user_metadata": {
    "email": "demo1@example.com"
  }
}

```

In this case, it appears as though the Pre-user registration hook is working correctly: The response contains both `app_metadata.email` and `user_metadata.email` fields.

### Create a user with pre-existing metadata

Post to [`/users`](https://auth0.com/docs/api/management/v2#!/Users/post_users) with the following data:

```json
{
  "connection": "Username-Password-Authentication",
  "email": "demo2@example.com",
  "password": "xX1234Xx",
  "user_metadata": {"foo": "bar"},
  "app_metadata": {"foo": "bar"}
}

```

Here’s the response (abridged to show relevant fields only):

```json
{
  "email": "demo2@example.com",
  "user_metadata": {
    "foo": "bar",
    "email": "demo2@example.com"
  },
  "email_verified": false,
  "app_metadata": {
    "foo": "bar"
  }
}

```

There’s something odd about this response: the `app_metadata` object includes the `foo` property, but the `email` property is missing. Meanwhile, the `user_metadata` object contains both the `foo` and `email` properties, which suggests that the Pre-user registration hook has actually fired.

I think this is a bug in the Pre-user registration hook.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 18, 2018, 4:35pm UTC](https://community.auth0.com/t/pre-user-registration-hook-doesnt-merge-app-metadata/10585/3 "2018-12-18T16:35:07Z")

</div>

Hey @drewneil

As it has been more than a few months since this topic was opened and there has been no reply or further information provided from the community as to the existence of the issue we would like to check if you are still facing the described challenge?

We are more than happy to assist in any way! If the issue is still out there please let us know so we can create a new thread for better visibility, otherwise we’ll close this one in week’s time.

Thank you!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 24, 2018, 5:14pm UTC](https://community.auth0.com/t/pre-user-registration-hook-doesnt-merge-app-metadata/10585/4 "2018-12-24T17:14:25Z")

</div>

This topic was automatically closed after 6 days. New replies are no longer allowed.
