# Set user metadata on registration from a react app

**URL:** <https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448>\
**Category:** Get Help\
**Created:** [July 20, 2021, 11:24am UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448 "2021-07-20T11:24:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hello10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hello10/32/13404_2.png) [@hello10](https://community.auth0.com/u/hello10)\
**Post date:** [July 20, 2021, 11:24am UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/1 "2021-07-20T11:24:01Z")

</div>

Hi,

I am using the React SDK to generate the registration link with `loginWithRedirect` and from there I would like to set metadata when the user registers. Is there a way to so?

Thank you

---

<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:** [July 20, 2021, 9:30pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/3 "2021-07-20T21:30:27Z")

</div>

Hi @hello10,

Welcome to the Auth0 Community!

You can pass params to Auth0 from your React app like this:

```auto
loginWithRedirect({favorite_color:'blue'})

```

And you can access those params from [post login actions](https://auth0.com/docs/actions/triggers/post-login) like this:

```javascript
event.request.query.favorite_color

```

You can set metadata in that action too, like this:

```javascript
/**
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
 */
exports.onExecutePostLogin = async (event, api) => {
  if(event.request.query.favorite_color) {
      api.user.setUserMetadata("favorite_color", event.request.query.favorite_color);
  }
};

```

---

<div class="post-metadata">

**Author:** ![hello10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hello10/32/13404_2.png) [@hello10](https://community.auth0.com/u/hello10)\
**Post date:** [July 21, 2021, 3:38pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/5 "2021-07-21T15:38:56Z")

</div>

> [@dan.woda](#):
>
> And you can access those params from [post login actions](https://auth0.com/docs/actions/triggers/post-login) like this:

Thank you. However my question was about regitration only, not login action and the `query` object is not available on registration actions.

---

<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:** [July 21, 2021, 3:42pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/6 "2021-07-21T15:42:07Z")

</div>

You can use the login action to add it _on first login._ What is an example of the information so I can help you figure out how to add it?

---

<div class="post-metadata">

**Author:** ![hello10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hello10/32/13404_2.png) [@hello10](https://community.auth0.com/u/hello10)\
**Post date:** [July 21, 2021, 3:43pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/7 "2021-07-21T15:43:58Z")

</div>

@ dan.woda It is a referral flag, if the user registers when coming from a referral, then I want to add a flag to his profile, however, this should only happen on registration and not on subsequent logins

---

<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:** [July 21, 2021, 4:49pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/8 "2021-07-21T16:49:40Z")

</div>

You can use the logins count stat to determine if it is a first login:

> `event.stats`
> 
> Login statistics for the current user.
> 
> Includes the following properties:
> 
> `logins_count` Number. The number of times this user has logged in.

Here is [the reference](https://auth0.com/docs/actions/triggers/post-login/event-object).

---

<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:** [August 5, 2021, 4:49pm UTC](https://community.auth0.com/t/set-user-metadata-on-registration-from-a-react-app/66448/9 "2021-08-05T16:49:50Z")

</div>

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