# Does Lock 10 additionalSignUpFields overwrite user\_metadata added in pre-registration hook

**URL:** <https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123>\
**Category:** Get Help\
**Tags:** lock-10, pre-user-registratio, user\_metadata\
**Created:** [June 17, 2017, 4:41am UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123 "2017-06-17T04:41:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zenanbach](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@zenanbach](https://community.auth0.com/u/zenanbach)\
**Post date:** [June 17, 2017, 4:41am UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/1 "2017-06-17T04:41:16Z")

</div>

I have an app where I would like to:

1. Require a couple of additional fields at signup.
2. Call a pre-registration hook that searches a legacy user database (non-Auth0) and adds to `user_metadata` based on results of the old database.

However, when I fire the pre-registration hook, and get a successful response - I can verify the validity of the `user_metadata` object before supplying to Auth0 - it seems the fields coming from Lock are the only `user_metadata` fields that get added.

I am following the guide for this extensibility point, and my `cb` looks like `cb(null, response)` where response is:

```
response.user = {
  user_metadata: { /* ... */ },
  app_metadata: { /* ... */ }
}

```

I can verify that `app_metadata` makes it to my user’s profile. But `user_metadata` gets overwritten it seems. Is this expected behavior?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 20, 2017, 4:55pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/2 "2017-06-20T16:55:51Z")

</div>

I have reproduced the behavior you described and I’m currently reviewing it further to verify if this is expected or not. Will let you know as soon as I additional information.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 20, 2017, 6:16pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/3 "2017-06-20T18:16:20Z")

</div>

I reviewed the situation and this is incorrect behavior; I already reported the situation internally and it’s being tracked in our backlog, however, I can’t provide you with a definitive timeline for when it will be addressed.

As a workaround you should be able to implement similar functionality from within a rule, although, you would need to keep track of additional flags for performance reasons given rules execute for each authentication transaction.

For example, you could perform the following steps in a rule:

1. Check for the presence of a truthy flag in `app_metadata` that indicates if user metadata has been already initialized.
2. If the flag exists and it’s truthy, return from the rule without additional processing, if not move to the next step.
3. Obtain the user metadata from your legacy database and [update the user](https://auth0.com/docs/rules/current/metadata-in-rules#updating-app_metadata-and-user_metadata-simultaneously) with the merged set of user metadata.
4. Set a flag to true in `app_metadata` to signal that user metadata has been initialized for this user.

---

<div class="post-metadata">

**Author:** ![zenanbach](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@zenanbach](https://community.auth0.com/u/zenanbach)\
**Post date:** [June 20, 2017, 6:41pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/4 "2017-06-20T18:41:29Z")

</div>

Hi @jmangelo.  
Thank you for looking into this. Ok, I figured this was the case, hooks being still in beta, relatively new feature. I have implemented a rule in the meantime, similar to what you describe. Though, instead of a truthy flag, I am only calling the database on the first login, i.e., signup. Through context.stats.loginsCount. It seems to do the trick.  
Thanks again!  
Zach

---

<div class="post-metadata">

**Author:** ![zenanbach](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@zenanbach](https://community.auth0.com/u/zenanbach)\
**Post date:** [June 20, 2017, 6:41pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/5 "2017-06-20T18:41:29Z")

</div>

Hi @jmangelo.  
Thank you for looking into this. Ok, I figured this was the case, hooks being still in beta, relatively new feature. I have implemented a rule in the meantime, similar to what you describe. Though, instead of a truthy flag, I am only calling the database on the first login, i.e., signup. Through context.stats.loginsCount. It seems to do the trick.  
Thanks again!  
Zach

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 20, 2017, 6:43pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/6 "2017-06-20T18:43:51Z")

</div>

Yeah, any mechanism that allows you to bypass processing after initializing metadata for the first time is fine.

---

<div class="post-metadata">

**Author:** ![zenanbach](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@zenanbach](https://community.auth0.com/u/zenanbach)\
**Post date:** [June 20, 2017, 9:48pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/7 "2017-06-20T21:48:57Z")

</div>

Great,  
I’ve updated my code to your specs. Setting a flag in app\_metadata actually suits my use case better than a first time login check.  
Also, please do let me know when this is scheduled to be patched. If there is a github issue, I’d be curious to follow along on the progress. Thanks.  
zach

---

<div class="post-metadata">

**Author:** ![zenanbach](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@zenanbach](https://community.auth0.com/u/zenanbach)\
**Post date:** [June 20, 2017, 9:48pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/8 "2017-06-20T21:48:57Z")

</div>

Great,  
I’ve updated my code to your specs. Setting a flag in app\_metadata actually suits my use case better than a first time login check.  
Also, please do let me know when this is scheduled to be patched. If there is a github issue, I’d be curious to follow along on the progress. Thanks.  
zach

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 20, 2017, 10:39pm UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/9 "2017-06-20T22:39:55Z")

</div>

I’ll keep that in mind, it’s not a public repository so there’s no visible way for you to track it directly.

---

<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:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/does-lock-10-additionalsignupfields-overwrite-user-metadata-added-in-pre-registration-hook/7123/10 "2018-03-02T05:54:44Z")

</div>


