# Pre-Registration action doesn't get executed?

**URL:** <https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [February 26, 2023, 9:14pm UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316 "2023-02-26T21:14:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![StuStu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@StuStu](https://community.auth0.com/u/StuStu)\
**Post date:** [February 26, 2023, 9:14pm UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316/1 "2023-02-26T21:14:55Z")

</div>

I have created a pre-registration action to add to the user’s metadata.  
The test runs succesfully, yet after registration, the new user does not have the updated metadata.

- Create Pre-User Registration Action (Node 16)
- Add code + Deploy
- Add action in the Pre-User registration flow + Save
- Register
- Metadata remains empty

```auto
exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setAppMetadata("AppTest", "App Works!");
  api.user.setUserMetadata("UserTest", "User Works!");  
};

```

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/8/a8a1205fed901ead3ca36e9f786f5915d2b538b9.png)

Do I still have to link the flow to my application somewhere maybe?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [February 28, 2023, 1:41am UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316/3 "2023-02-28T01:41:52Z")

</div>

Hey @StuStu !

Thanks for the detailed explanation and diagram, very helpful. Unfortunately both pre and post user registration Actions are available for database (non-federated) connections only at this time. Please feel free to add your feedback to the following request as this is definitely a hot topic 🔥

> [@Trigger the Pre User Registration flow for social and other non-database connection types](https://community.auth0.com/t/trigger-the-pre-user-registration-flow-for-social-and-other-non-database-connection-types/81070):
>
> Feature: Provide a short title of your feature request/feedback. Trigger the Pre User Registration flow for social and other non-database connection types. Description: Give us some details about your feedback/feature request. Examples, screenshots, videos, etc. are helpful. For some reason, the Pre User Registration flow does not run for social or other non-database connection types. This makes it impossible to: Create a corresponding user in an external database, before the user is regist…

Thanks!

---

<div class="post-metadata">

**Author:** ![StuStu](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@StuStu](https://community.auth0.com/u/StuStu)\
**Post date:** [March 10, 2023, 2:30pm UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316/4 "2023-03-10T14:30:22Z")

</div>

Instead I have now created the following **rule** , which _ **seems** _ to work (code borrowed from the Salesforce example):

```auto
function (user, context, callback) {
  user.app_metadata = user.app_metadata || {};
  let userid = user.app_metadata.userid;
  context.accessToken.role = "webuser";
  context.accessToken.userid = userid;
  
  if (userid) {
    return callback(null, user, context);
  }
  var request = require('request');
  request.get('http://mybackend/new_userid', {
    qs: {
      check_email: user.email
    },
    json: true
  },
  (err, response, body) => {
    if (err) return callback(err);
    if (response.statusCode === 200) {
      context.accessToken.userid = body;
    }
    return callback(null, user, context);
  });
}

```

This function [http://mybackend/new\_userid](http://mybackend/new_userid), returns a new or existing (if email already in the database) userid.

I am not entirely clear on WHEN actions are executed. But, at least (and I think only) at authentication, so this should be executed for new and existing users, right?

UPDATE: Actually, not. It only works in the Auth0-sandbox. Is this the same reason here? Are Rules only available to database (non-federated) connections?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 10, 2023, 10:38pm UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316/5 "2023-03-10T22:38:33Z")

</div>

Hey @StuStu!

> [@StuStu](#):
>
> I am not entirely clear on WHEN actions are executed. But, at least (and I think only) at authentication, so this should be executed for new and existing users, right?
> 
> UPDATE: Actually, not. It only works in the Auth0-sandbox. Is this the same reason here? Are Rules only available to database (non-federated) connections?

Rules are executed during authentication only (when a post login action would execute) and will apply to new users created/authenticating for the first time as well as existing users.

Both rules and actions are available for federated/social connections at login, but not pre or post user registration in the case of actions.

---

<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 24, 2023, 10:38pm UTC](https://community.auth0.com/t/pre-registration-action-doesnt-get-executed/101316/6 "2023-03-24T22:38:57Z")

</div>

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