I am having issues with the synchronous pre-registration hook. Any advise is highly appreciated.
The context is as follows:
- When I SignUp I want to leverage the pre-registration hook
- The hook should call a GET Rest-API (tried it with the got library)
- 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’)]).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();
};