Post Registration Hook - User Properties Not Pulling In

Hi,

We are currently using a post registration web-hook to do a bit of custom functionality.
The JSON used when testing the web-hook through the interface looks like this

{
  "user": {
    "id": "abc123",
    "tenant": "my-tenant",
    "name":"Testing",
    "username": "user1",
    "email": "user1@foo.com",
    "emailVerified": true,
    "phoneNumber": "1-000-000-0000",
    "phoneNumberVerified": true,
    "user_metadata": {
      "hobby": "surfing"
    },
    "app_metadata": {
      "plan": "full"
    }
  },
  "context": {
    "requestLanguage": "en-us",
    "connection": {
      "id": "con_xxxxxxxxxxxxxxxx",
      "name": "Username-Password-Authentication",
      "tenant": "my-tenant"
    }
  }
}'

When printing out the user object i can see that the name property is set. However when creating a user using the /dbconnections/signup on the management API, setting any of the other use properties such as name, given_name, nickname etc, these don’t pull through into the hook when i print out the user object.

It seems silly to have to set the name in the user_metadata property to access it

Thanks

Hi @darren.tiplady,

when i print out the user object.

How do you print out the user? Is this in your client application, or via console log in the hook and checking the webtask realtime logs (asking cause the latter wouldn’t work in a post-reg hook due to asynchronisity)?

What’s the code of your hook?

Hi Mat,

The user is being printed out when i was testing the hook via the webtask realtime logs. Screenshot below.

When testing from my application i let the code run through the management API’s endpoint

/dbconnections/signup

I then checked the log of the web-hook to see what the user object is that was printed out was. As an example this is what was printed out .

image

Webhook below.

/**
@param {object} user - The user being created
@param {string} user.id - user id
@param {string} user.tenant - Auth0 tenant name
@param {string} user.username - user name
@param {string} user.email - email
@param {boolean} user.emailVerified - is e-mail verified?
@param {string} user.phoneNumber - phone number
@param {boolean} user.phoneNumberVerified - is phone number verified?
@param {object} user.user_metadata - user metadata
@param {object} user.app_metadata - application metadata
@param {object} context - Auth0 connection and other context info
@param {string} context.requestLanguage - language of the client agent
@param {object} context.connection - information about the Auth0 connection
@param {object} context.connection.id - connection id
@param {object} context.connection.name - connection name
@param {object} context.connection.tenant - connection tenant
@param {object} context.webtask - webtask context
@param {function} cb - function (error, response)
*/
module.exports = function (user, context, cb) {

    console.log('User: o%', user);
    
    // Constants
    const request = require('request-promise');
    const sgMail = require('@sendgrid/mail');
    const auth0verificationEmailUrl = 'https://lawyerly-internal.eu.auth0.com/api/v2/email-templates/verify_email';
    const sendGridApiKey = context.webtask.secrets['sendgrid-apikey'];
    const firmSignupClientId = context.webtask.secrets['firm-signup-client-id'];
    const firmSignupClientSecret = context.webtask.secrets['firm-signup-client-secret'];
    
    // Email Replacement Variables
    const displayName = user.user_metadata.firstname;
    const user_id = 'auth0|' + user.id;
    var verify_email_Template;
    
    // Auth0 Access Token
    var accessToken;
    
    // Auth0 Access Token Request Options
    var accessTokenOptions = {
        method: 'POST',
        url: 'https://lawyerly-internal.eu.auth0.com/oauth/token',
        form:{
          grant_type: 'client_credentials',
          client_id: firmSignupClientId,
          client_secret: firmSignupClientSecret,
          audience: 'https://lawyerly-internal.eu.auth0.com/api/v2/'
        },
        resolveWithFullResponse: true
    };
  
    // Main Request
    request(accessTokenOptions)
        .then(function onSuccess(response) {
            if (response.statusCode == 400)
                console.log('Invalid model received %o', response);
            if (response.statusCode == 200) {
                // Save the access token
                accessToken = JSON.parse(response.body);
            }
            
            // Auth0 Verification Email Settings
            var verifyEmailOptions = {
                method: 'GET',
                url: auth0verificationEmailUrl,
                headers: { 'Authorization': 'bearer ' + accessToken.access_token },
                resolveWithFullResponse: true
            };
            
            // Get the verification email template
            request(verifyEmailOptions)
                .then(function onSuccess(response) {
                    if (response.statusCode == 400)
                        console.log('Invalid model received %o', response);
                    if (response.statusCode == 200) {
                        verify_email_Template = response.body.replace(/user_id/g, user_id)
                            .replace('{{ user.app_metadata.displayName }}', displayName);
                        
                        // Parse Template to JSON
                        jsonVerificationTemplate = JSON.parse(verify_email_Template);
        
                        // Setup SendGrid Email
                        sgMail.setApiKey(sendGridApiKey);
                        const msg = {
                            to: user.email,
                            from: jsonVerificationTemplate.from,
                            subject: jsonVerificationTemplate.subject,
                            content: [
                                {
                                    type: 'text/html',
                                    value: jsonVerificationTemplate.body
                                }]
                        };
        
                        // Send mail
                        sgMail
                            .send(msg)
                            .then(() => {
                                console.log('Success SendGrid Mail Sent');
                            })
                            .catch(error => {
                                //Log friendly error
                                console.error(error.toString());
        
                                //Extract error msg
                                const { message, code, response } = error;
        
                                //Extract response msg
                                const { headers, body } = response;
                            });
                    }
        
                    // Ensure callback is called on each path
                        cb();
                    }).catch(function onError(err) {
                        console.error(error.toString());
                        cb();
                    });
            
            
            // Ensure callback is called on each path
            cb();
        }).catch(function onError(err) {
            console.error(error.toString());
            cb();
        });
};

To add to this, user.picture is also not available during the post-registration hook even though it is part of the normalized user profile.

1 Like

Any updates on this please? I’m facing the same problem.

Same problem here. Any updates…? It’s been a while now