Post Password Change Action is failing | api coming in nil

We’re currently in full swing of an updating our test env to handle the latest v4 changes with our actions. We of course, came across some methods that began to fail and proceeded to update the logic. Currently, I am unable to update the user_metadata as a result of the api returning a nil object when the post password change action is run. Please review the action below, to ensure that we all know what is taking place.

  "date": "2025-02-19T00:23:56.342Z",
  "type": "fcph",
  "description": "TypeError on post-change-password: Cannot read properties of undefined (reading 'sendUserTo')",
  "connection": "our-connection-to-database",

const axios = require("axios");
const ManagementClient = require('auth0').ManagementClient;

exports.onExecutePostChangePassword = async (event, api) => {

  if(event.request.method === 'PUT'){
    return;
  }

  const managementClient = new ManagementClient({
        clientId: event.secrets.CLIENT_ID,
        clientSecret: event.secrets.CLIENT_SECRET,
        domain: event.secrets.DOMAIN,
        scope: 'create:user_tickets',
      });
  const params =  { id : event.user.user_id};
  const data = { "user_metadata":{"id": event.user.user_id, "force_password_change": null,  "last_password_reset": null}};

  try {
    const res = await managementClient.users.update(params, data)
  } catch (e) {
    console.log(e)
  }
 api.redirect.sendUserTo(`https://${event.secrets.AUTH0_CUSTOM_DOMAIN}/v2/logout?returnTo=https://${event.secrets.HIDDEN_DOMAIN}/?state=pw_reset`);
};

Last note, I modified the scope to add update:users/update:current_user_metadata – yet the test user while the simulation runs – is coming back as not found.
ManagementApiError: The user does not exist.

Hi @dwood1,

The error indicates that you used an invalid method, particularly when calling api.redirect.sendUserTo().

I have checked our Actions Triggers: post-change-password - API Object documentation and confirmed that there isn’t a redirect method available.

This is only available in the onExecutePostChallenge trigger.

If you would like the user to be redirected to a specific URL after they have reset their password, you can set that value in your Change Password (link) email template under the "Redirect To’ field.

For more details, I recommend referring to our Password Change Redirect Behavior knowledge solution.

Cheers,
Rueben

After moving the redirect logic – it is in fact working. Thank you.

1 Like

Hi @dwood1,

I’m glad the redirect logic is working now.

Let us know if there’s anything else we can do to help!

Cheers,
Rueben