# Auth0 post registration action doesn't work

**URL:** <https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355>\
**Category:** Get Help\
**Created:** [August 22, 2021, 3:01pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355 "2021-08-22T15:01:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.varga](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steven.varga/32/31288_2.png) [@steven.varga](https://community.auth0.com/u/steven.varga)\
**Post date:** [August 22, 2021, 3:01pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/1 "2021-08-22T15:01:37Z")

</div>

On behalf of a corporate client I am using auth0; added the required functionality by using post registration action, as recommended on your [hooks page](https://manage.auth0.com/dashboard/us/h5cluster-hdf/hooks):

```auto
We recommend you to explore Actions, our newest
extensibility product now in General Availability. 

```

Then my personal experience lead me to reading [this post](https://community.auth0.com/t/actions-flows-not-executing/62769) that this is a _fire and forget_ architecture, and only the last component is functional.  
Would it be possibly to remove the **recommendation** of _actions_ on rule page until **fire** component works as well?

---

<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:** [August 23, 2021, 8:42pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/3 "2021-08-23T20:42:20Z")

</div>

Hi @steven.varga,

Thanks for reaching out.

The post registration hook should work the same way as the post registration action. It is asyncronous to the rest of the Auth0 pipeline and should be treated with the same _fire and forget_ expectations. Can you tell me more about your use-case so I can understand what is happening differently between the hook and action?

---

<div class="post-metadata">

**Author:** ![steven.varga](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steven.varga/32/31288_2.png) [@steven.varga](https://community.auth0.com/u/steven.varga)\
**Post date:** [August 23, 2021, 9:15pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/4 "2021-08-23T21:15:40Z")

</div>

Hi Dan,  
Thanks for getting back!

The use case is to obtain a unique posix user ID for registered users. The `Actions` were recommended, but somehow never fired when tested with database connection, the `hooks` did. As of now, I am rather short on time to verify this `Action` business for you…

Making things more complicated, I realised that when using socials the flow doesn’t go through `hooks`, so I reached for `rules`. Oh but the same script using `aws-sdk` doesn’t run under `rules`. Another few hours and two cups of coffee, it appeared that the `aws-sdk@version` are different, and probably the ones available under `rules` may not function properly ([filed it under community bug](https://community.auth0.com/t/aws-sdk-dynamo-db-doesnt-execute-query-in-rules/68416))…

Currently I am working on an alternative solution, only 14hrs left in the time budget, so I am working on alternatives.  
If you happened to know why [this approach](https://community.auth0.com/t/aws-sdk-dynamo-db-doesnt-execute-query-in-rules/68416) please let me know.

of course, there is a chance I overlooked something obvious, in that case sorry for the noise!  
best wishes: steven

---

<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:** [August 24, 2021, 8:25pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/5 "2021-08-24T20:25:52Z")

</div>

If you require this function to run for every user; social, database, or otherwise, then you will need to use a post login Action _or_ a Rule.

I would suggest using an Action, as it is the successor to Rules and gives you access to a richer feature-set than Rules (versioning, full npm library, improved logging, etc.).

With that said, it is completely possible to achieve this with a Rule as well. Just be aware that rules have access to a [limited set of npm modules](https://auth0-extensions.github.io/canirequire/#aws-sdk) and will be likely deprecated at some point in the future.

As for the execution, I would suggest using this type of flow with a **post-login Action** :

```auto
/**
 * @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.
 */

//I am using aws-sdk@2.458.0 to stay consistent with your code, but you could use any version you prefer.
const AWS = require('aws-sdk');

exports.onExecutePostLogin = async (event, api) => {

  //If the user has already been added to the DB, skip this action
  if (event.user.app_metadata.addedToDynamoDB) {
    return;
  }
  
  //Otherwise, perform the database operation
  const db = new AWS.DynamoDB({
    accessKeyId: event.secrets.AWS_KEY_ID, 
    secretAccessKey: event.secrets.AWS_SECRET, 
    region: event.secrets.AWS_REGION
  });

  try{
    console.log("adding the user to DynamoDB");
    const results = await db.listTables({}).promise();
    //...add your call to add the user to DynamoDB

    // Update the user's app metadata to indicate they have been added to the db
    console.log("successfully added user to DynamoDB");
    api.user.setAppMetadata("addedToDynamoDB", "true");
  } catch (err) {
    console.log(err)
  }
};

```

Does that make sense? I wasn’t sure if you are trying to retrieve a user ID or add a user ID to dynamo, but you should be able to do either one. The important piece here is that you are using a flag in the user’s app\_metadata to indicate the operation has been completed. This operation should only run on the first login (unless there is an error from AWS, then it will try again on the next login), and any future logins will skip this operation because of the flag.

---

<div class="post-metadata">

**Author:** ![steven.varga](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steven.varga/32/31288_2.png) [@steven.varga](https://community.auth0.com/u/steven.varga)\
**Post date:** [August 24, 2021, 9:35pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/6 "2021-08-24T21:35:44Z")

</div>

Hi Dan,  
I uploaded the follwing:

```auto
var AWS = require("aws-sdk");
exports.onExecutePostLogin = async (event, api) => {
  try{
    console.log("adding the user to DynamoDB");
    api.user.setAppMetadata("addedToDynamoDB", "true");
  } catch (err) {
    console.log(err)
  }
};

```

Then from database connections clicked on **Try Connection** , used database login, filled in the login form, and had a confirmed login.  
Check user record for app metadata: **nothing** , checked for logs, **no trace action ever run**.

steve

---

<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:** [August 24, 2021, 9:53pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/7 "2021-08-24T21:53:59Z")

</div>

It sounds like you need to deploy the action. Can you confirm you have saved the action _and_ added it to the post login action flow and applied the settings?

---

<div class="post-metadata">

**Author:** ![steven.varga](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/steven.varga/32/31288_2.png) [@steven.varga](https://community.auth0.com/u/steven.varga)\
**Post date:** [August 24, 2021, 10:15pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/8 "2021-08-24T22:15:29Z")

</div>

Hi Dan,  
that did it, thanks a lot!

---

<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:** [August 24, 2021, 10:16pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/9 "2021-08-24T22:16:23Z")

</div>

Glad that worked for you. Let us know if you have any other questions.

---

<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:** [September 8, 2021, 10:17pm UTC](https://community.auth0.com/t/auth0-post-registration-action-doesnt-work/68355/10 "2021-09-08T22:17:18Z")

</div>

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