PHP - get updated credentials, while user is logged in

Hi @toomuchtimeondocs ,

Based on my tests and the documentation for the the post-login Action, unfortunately updating the user profile data occurs at the end of the action(s) within a flow. So if within a particular action you change a user metadata value from, for example, false to true AND you use this value (referencing an object) as a value for the custom claim, at first your claim will consists of the old value (false) and during another action run, it will take the updated value.

An example:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
  const  preffered_contact  = event.user.email;
  api.user.setUserMetadata("new_metadata_key", preffered_contact);

  //the below metadata currently takes value "flase" and we update it to "true" at the end of this action (at the end of all actions in this flow)
  api.user.setUserMetadata("another_new_metadata_key", true);


    // Set claims 
    //the below claim will be addedd durig the first login as we do not refer to a user metadata value that has been updated now
    api.accessToken.setCustomClaim(`${namespace}/preferred_contact`, event.user.email);

    //the below claim will be updated with the new value starting from the second time the action will run as we refer to the usermetadata that is currently being updated
    api.accessToken.setCustomClaim(`${namespace}/another_new_metadata_key`, event.user.user_metadata.another_new_metadata_key);
  };

If you would like to check an example of updating user metadata via the Management API, here’s a good topic for that.

Please let me know if you would like to discuss it further. Thanks!


:video_camera: Want to join our next Community Interactive Q&A with our experts? This time we’re gonna talk about Auth0 Terraform Provider