# Adding user metadata in the pre-user registration hook

**URL:** <https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665>\
**Category:** Get Help\
**Tags:** user\_metadata, login, auth0\
**Created:** [November 22, 2020, 8:44pm UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665 "2020-11-22T20:44:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredgalanis1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jaredgalanis1/32/12805_2.png) [@jaredgalanis1](https://community.auth0.com/u/jaredgalanis1)\
**Post date:** [November 22, 2020, 8:44pm UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665/1 "2020-11-22T20:44:09Z")

</div>

Hi, I’d like to access user\_metadata in the pre-user registration hook. My use case is to use some of the metadata passed to webAuth.redirect.signupAndLogin to make an external request in the hook and then add to the user\_metadata with the response I get from that external request.

However it appears that the metadata I am passing to webAuth.redirect.signupAndLogin is not available there. That metadata is available in the user-post registration hook (but my understanding is that I cannot add to user\_metadata in the post registration hook), furthermore the metadata does get set on the user when I view it in the auth0 web interface, but that metadata isn’t returned in when requesting the user’s profile.

Am I missing something or is it not possible to access metadata passed to webAuth.redirect.signupAndLogin in the pre registration hook?

Also is it not possible to add to user metadata in the post registration hook?

I don’t think I can do this work in a rule because I need to make the external request with secret credentials and I don’t see any way to set a secret in a rule.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 23, 2020, 4:31pm UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665/3 "2020-11-23T16:31:05Z")

</div>

Hi @jaredgalanis1,

Welcome to the Community!

I think you should be able to do what you are describing. Can you share your code so I can trouble shoot the issues? Here is a thread that describes how to send a param to the pre reg hook:

> [@Hook/lock custom parameter](https://community.auth0.com/t/hook-lock-custom-parameter/7582):
>
> I’m passing a custom parameter to the lock with no issues: webAuth.authorise({ foo: ‘bar’ }); I’d like to be able to access this parameter in the pre-registration hook, but can’t figure out if there is a way to do this.

and here is a thread that describes how to add it to the user\_metadata property:

[https://community.auth0.com/t/set-user-metadata-property-on-signup-hook/26516](https://community.auth0.com/t/set-user-metadata-property-on-signup-hook/26516)

> [@jaredgalanis1](#):
>
> furthermore the metadata does get set on the user when I view it in the auth0 web interface, but that metadata isn’t returned in when requesting the user’s profile.

This issue is because it isn’t automatically returned in the user profile. Here is a thread that shows how to set up a rule that returns user\_metadata in the id token:

[https://community.auth0.com/t/when-successful-login-id-token-has-not-the-user-metadata/12400/2](https://community.auth0.com/t/when-successful-login-id-token-has-not-the-user-metadata/12400/2)

> [@jaredgalanis1](#):
>
> I don’t think I can do this work in a rule because I need to make the external request with secret credentials and I don’t see any way to set a secret in a rule.

It is actually possible to do this in rules, and if you are wanting to add this property to social users you would have to do this in a rule. Hooks don’t run for non-database users.

You can add credentials in rules in the configuration object:

> **[Store Rule Configurations - Auth0 Docs](https://auth0.com/docs/customize/rules/configuration)**
>
> Learn about the global configuration object in rules for storing commonly used values.

I know that is a lot of info so please let me know if you have questions!

---

<div class="post-metadata">

**Author:** ![jaredgalanis1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jaredgalanis1/32/12805_2.png) [@jaredgalanis1](https://community.auth0.com/u/jaredgalanis1)\
**Post date:** [December 1, 2020, 10:17am UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665/4 "2020-12-01T10:17:57Z")

</div>

Thanks for that @dan.woda! I ended up accessing the management API directly, but I’ll keep these tips in mind if I end up needing something like this in the future.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 1, 2020, 5:24pm UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665/5 "2020-12-01T17:24:10Z")

</div>

Sounds good. Thanks for the update!

---

<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:** [December 16, 2020, 7:19pm UTC](https://community.auth0.com/t/adding-user-metadata-in-the-pre-user-registration-hook/53665/6 "2020-12-16T19:19:26Z")

</div>

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