# Auth0 user uuid

**URL:** <https://community.auth0.com/t/auth0-user-uuid/71956>\
**Category:** Get Help\
**Created:** [October 25, 2021, 6:36am UTC](https://community.auth0.com/t/auth0-user-uuid/71956 "2021-10-25T06:36:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quintenps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/quintenps/32/32534_2.png) [@Quintenps](https://community.auth0.com/u/Quintenps)\
**Post date:** [October 25, 2021, 6:36am UTC](https://community.auth0.com/t/auth0-user-uuid/71956/1 "2021-10-25T06:36:39Z")

</div>

Hi all,

Lately I’ve been playing around with Auth0.  
I’ve managed to setup a custom action that generates an UUID and saves that to the user’s app\_metadata. However, this only works with regular user signups, not with SSO.

As @rueben.tiow said in [his post](https://community.auth0.com/t/auth0-pre-registration-hook-using-sso-registration/69695/5). The only trigger that works is the login trigger.

To come to my question: I’m looking for a solution to generate an UUID for all users, including SSO logins. Is this possible?

**Edit** : So appearently legacy rules do seem to work with SSO. With some help of @markd 's [rules](https://github.com/dmark/auth0-cli-utilities) i’ve managed to get it working.

I assume these rules will be deprected someday, would I be able to replace this with actions in some way?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 25, 2021, 3:30pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/3 "2021-10-25T15:30:37Z")

</div>

Hi @Quintenps,

Welcome to the Auth0 Community!

I’m glad to hear that you found a workaround using Rules and wanted to know more about the deprecation of Rules.

Yes, you are encouraged to convert your Rules into Actions if possible. At this time, we will continue to support Auth0 Rules until 2022.

Since long-term support for Node 12 will be ending in April 2022, we strongly recommend you begin to migrate to Auth0 Actions, which will allow you to stay on a supported Node version without additional future action or overhead. Note that we do not expect any replacement strategies to emerge until 2022.

For now, I can confirm that it’s safe to continue using Rules until the time comes for the migration.

By which point, you should have ample time to convert your Rules into Actions with the provided migration strategies.

Lastly, If you would like, I would be happy to look at your Rule and see if we can convert it into an Auth0 Action.

Thank you.

---

<div class="post-metadata">

**Author:** ![Quintenps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/quintenps/32/32534_2.png) [@Quintenps](https://community.auth0.com/u/Quintenps)\
**Post date:** [October 25, 2021, 3:37pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/4 "2021-10-25T15:37:34Z")

</div>

> [@rueben.tiow](#):
>
> Lastly, If you would like, I would be happy to look at your Rule and see if we can convert it into an Auth0 Action.

Sweet, yes please 🙂

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 25, 2021, 3:57pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/5 "2021-10-25T15:57:28Z")

</div>

Hi @Quintenps,

Thank you for the quick reply!

Could you please share with me the Rule you would like to convert into an Action?

Thank you.

---

<div class="post-metadata">

**Author:** ![Quintenps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/quintenps/32/32534_2.png) [@Quintenps](https://community.auth0.com/u/Quintenps)\
**Post date:** [October 25, 2021, 4:25pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/6 "2021-10-25T16:25:02Z")

</div>

Yeah for sure.

Basically I’m using 3 of Markd’s rules listed in [this repo](https://github.com/dmark/auth0-cli-utilities/tree/master/rules)

- [add-user-metadata-to-idtoken.js](https://github.com/dmark/auth0-cli-utilities/blob/master/rules/add-user-metadata-to-idtoken.js)
- [add-uuid-to-app-metadata.js](https://github.com/dmark/auth0-cli-utilities/blob/master/rules/add-uuid-to-app-metadata.js)
- [add-uuid-to-idtoken.js](https://github.com/dmark/auth0-cli-utilities/blob/master/rules/add-uuid-to-idtoken.js)

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 25, 2021, 9:46pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/7 "2021-10-25T21:46:07Z")

</div>

Hi @Quintenps,

Thank you for your response and patience!

First, you’ll need to configure **3 Post-Login Action** scripts.

Here is the equivalent code using Auth0 Actions:

```auto
//add-user-metadata-to-idtoken Action
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://sr2.ca/claims/";
  api.idToken.setCustomClaim(namespace + "user_metadata", event.user.user_metadata)
};

```

```auto
//add-uuid-to-app-metadata Action
exports.onExecutePostLogin = async (event, api) => {
  const { v4: uuidv4 } = require('uuid');
  event.user.app_metadata.uuid = event.user.app_metadata.uuid || uuidv4(); 
  api.user.setAppMetadata("uuid", event.user.app_metadata.uuid)
};

```

```auto
//add-uuid-to-idtoken Action
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://sr2.ca/claims/";
  api.idToken.setCustomClaim(namespace + "uuid", event.user.app_metadata.uuid);
};

```

In these Action scripts, I also did not implement an unnecessary line of code for setting the app\_metadata to itself, but is never used: `user.app_metadata = user.app_metadata || {};`

I have just tested these Action scripts myself and confirm that they work.

Here are some useful resources:

- [Post Login Action Event Object](https://auth0.com/docs/actions/triggers/post-login/event-object)
- [Post Login Action API Object](https://auth0.com/docs/actions/triggers/post-login/api-object)
- [Post Login Action Common Use Cases](https://auth0.com/docs/actions/triggers/post-login#common-use-cases)

Please let me know how this works for you.

Thank you.

---

<div class="post-metadata">

**Author:** ![Quintenps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/quintenps/32/32534_2.png) [@Quintenps](https://community.auth0.com/u/Quintenps)\
**Post date:** [October 26, 2021, 7:58am UTC](https://community.auth0.com/t/auth0-user-uuid/71956/8 "2021-10-26T07:58:54Z")

</div>

Thank you so much for your effort! I’m going to try this tonight. Just to be sure; does this also work with SSO?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 26, 2021, 4:30pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/9 "2021-10-26T16:30:30Z")

</div>

Hi @Quintenps,

Thank you for your reply!

Yes, this will work with SSO. These Action scripts will assign a UUID to a user logging in with any type of Connection such as Social Logins (Facebook, Google, etc) or Database Logins.

Please let me know if there’s anything else I can do to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![Quintenps](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/quintenps/32/32534_2.png) [@Quintenps](https://community.auth0.com/u/Quintenps)\
**Post date:** [October 26, 2021, 4:58pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/10 "2021-10-26T16:58:16Z")

</div>

I can’t thank you enough! It works!

I completely overlooked the post-login possibility. I was too focused on trying to generate an UUID on pre/post registration.

Sweet 😃

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 26, 2021, 4:59pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/11 "2021-10-26T16:59:46Z")

</div>

Hi @Quintenps,

You’re most welcome!

I’m happy to hear that everything works.

Have a great rest of your day!

---

<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:** [November 10, 2021, 5:00pm UTC](https://community.auth0.com/t/auth0-user-uuid/71956/12 "2021-11-10T17:00:00Z")

</div>

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