Auth0 Home Blog Docs

Post registration hook - user id

hooks

#1

Hi,

I need to access user.id in post registration hook, but it seems its undefined

module.exports = function(user, context, cb) {
  // Perform any asynchronous actions, e.g. send notification to Slack.
  request({
    method: 'POST',
    url: 'http://dumy.com/api',
    headers: {
      'Content-Type': 'application/json',
    },
    body: `{  "email": "${user.email}", "fkAuth": "${user.id}" }`
  }, function(error, response, body) {
    console.log(user)
    console.log(context)
    cb(error, response)
  });
};

In user there is no attribute id, is there any other option how to obtain it ?


#2

This was found to be a bug which has now been resolved. You can access the id through user.id.


#3

user.user_id is also undefined. This is user object, no ID inside

 { tenant: 'my-tenant',
  username: 'user1',
  email: 'user1@foo.com',
  emailVerified: true,
  phoneNumber: '1-000-000-0000',
  phoneNumberVerified: true,
  user_metadata: { hobby: 'surfing' },
  app_metadata: { plan: 'full' }
}

#4

Any update on this bug? user_id is not accessible in the post-registration hook


#5

How are you able to do a POST request? I’m getting a 500 error when I try to do a POST. =(


#6

Any update on this bug? user_id is not accessible in the post-registration hook


#7

user.user_id is also undefined. This is user object, no ID inside

 { tenant: 'my-tenant',
  username: 'user1',
  email: 'user1@foo.com',
  emailVerified: true,
  phoneNumber: '1-000-000-0000',
  phoneNumberVerified: true,
  user_metadata: { hobby: 'surfing' },
  app_metadata: { plan: 'full' }
}

#8

Thanks for pointing this out. We have resolved a bug that was causing this - you should now be able to use user.id.


#9

Hey! I still don’t get the id attribute in the user object. When I log it in the hook dev console, it’s undefined. Any update?


#10

To the Auth0 team: I confirm that it’s impossible get the id attribute in the user object. Her’s what I get when I log it in the hooks dev console:`

{ user: { tenant: 'my-tenant', username: 'user1', email: 'user1@foo.com', emailverified: true, phonenumber: '1-000-000-0000', phonenumberverified: true, user_metadata: { hobby: 'surfing' }, app_metadata: { plan: 'full' } } } 

#11

This bug is happening again, the user object does not have an id.


#12

This bug is happening again, the user object does not have an id.


#13

@kangarup @kaumac I am looking into this on my end.


#14

@kangarup @kaumac can you confirm whether this issue is still happening for you? I have tested on my tenant and see user.id.


#15

@prashant it is actually working, sorry for my mistake. I just didn’t have an id on the request body on the webtask editor. But when the hook is actually called from a real event, the id is there.


#16

@christiankindhealth thanks for pointing this out. We found a bug which has been resolved - you should now have access to user.id.


#17