How to Pass Transient Data Between Actions

Overview

With Rules, it was possible to pass custom data between rules through the user object. With Actions, the event.user object is read-only, so this is no longer possible. This article will explain a potential workaround.

Applies To

  • Actions
  • Rules to Actions Migration

Solution

Use the api.user.setAppmetada methods, and in the last action, set the metadata fields to “undefined”, so the user profile isn’t updated.

Step#1: Action1 Sets AppMetdata and UserMetadata via api.user

exports.onExecutePostLogin = async (event, api) => {
  api.user.setUserMetadata('user_theme', 'light');
  api.user.setAppMetadata('app_scope', 'app:read app:write');
};

Step#2: Action2 and subsequent executed actions can read the values in the event.user object.

exports.onExecutePostLogin = async (event, api) => {
  console.log(event.user.user_metadata.user_theme);
  console.log(event.user.app_metadata.app_scope);
};

Step3#: Auth0 is not updating the user via Management API call when the metadata fields are set to undefined.

exports.onExecutePostLogin = async (event, api) => {
  api.user.setAppMetadata('user_theme', undefined);
  api.user.setAppMetadata('app_scope', undefined);
};

Related References