# Pre-Registration Hook

**URL:** <https://community.auth0.com/t/pre-registration-hook/56382>\
**Category:** Get Help\
**Tags:** hooks\
**Created:** [January 18, 2021, 5:04pm UTC](https://community.auth0.com/t/pre-registration-hook/56382 "2021-01-18T17:04:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai.schwidder](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kai.schwidder/32/12789_2.png) [@kai.schwidder](https://community.auth0.com/u/kai.schwidder)\
**Post date:** [January 18, 2021, 5:04pm UTC](https://community.auth0.com/t/pre-registration-hook/56382/1 "2021-01-18T17:04:03Z")

</div>

I am having issues with the synchronous pre-registration hook. Any advise is highly appreciated.  
The context is as follows:

1. When I SignUp I want to leverage the pre-registration hook
2. The hook should call a GET Rest-API (tried it with the got library)
3. According to the response of the REST-API I have to return the proper callback for AUTH0

ISSUE:

REST Calls are asynchronous BUT the pre-registration has to be synchronous. How to achieve to synchronously call the REST Backend ?

This synchronous approach of the signup should be otherwise revised.

Current code example.

const got = require(‘got’);

module.exports = function (user, context, cb) {  
var response = {};

response.user = user;

async function test () {

await Promise.all([got(‘[https://apidev.coshare.ch/api/config](https://apidev.coshare.ch/api/config)’)]).then(  
values =\> {  
var result = values[0].body;

response.user.user\_metadata.coshare = result;  
console.log(“RESULT NEW”);  
console.log(response);  
cb(null, response);  
}  
);  
// Add user or app metadata to the newly created user  
// response.user.user\_metadata = { foo: ‘bar’ };  
// response.user.app\_metadata = { vip: true, score: 7 };

// Deny the user’s registration and send a localized message to New Universal Login  
// if (denyRegistration) {  
// const LOCALIZED\_MESSAGES = {  
// en: ‘You are not allowed to register.’,  
// es: ‘No tienes permitido registrarte.’  
// };  
//  
// const localizedMessage = LOCALIZED\_MESSAGES[context.renderLanguage] || LOCALIZED\_MESSAGES[‘en’];  
// return cb(new PreUserRegistrationError(‘Denied user registration in Pre User Registration Hook’, localizedMessage));  
// }

console.log(“DONE”)  
}

test();  
};

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [January 19, 2021, 3:55pm UTC](https://community.auth0.com/t/pre-registration-hook/56382/3 "2021-01-19T15:55:14Z")

</div>

Hi @kai.schwidder,

Welcome to the Community!

Just to clarify, could you talk a little bit more about what you’d like to use the pre-registration hook for?  
Are you finding that the callback (`cb`) being called before the response is received?

I think you may need to update the async/await code a little:

```auto
const got = require('got');

module.exports = async function (user, context, cb) {
  var response = {};

  response.user = user;
  try {
    var values = await got('https://apidev.coshare.ch/api/config');
    var result = JSON.parse(values.body);
    response.user.user_metadata.coshare = result;
    console.log('RESULT NEW');
    console.log(user);
    cb(null, user, context);
  } catch (e) {
    console.log(e)
  }
};

```

You may find this FAQ helpful as well: [Is it possible to use async await in rules?](https://community.auth0.com/t/is-it-possible-to-use-async-await-in-rules/50235)

---

<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:** [February 3, 2021, 3:55pm UTC](https://community.auth0.com/t/pre-registration-hook/56382/4 "2021-02-03T15:55:29Z")

</div>

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