Rules are working in the debug console, but they don't work when you use them

I used Rules for want to include user.email in the jwt payload. Rules code is below.

function (user, context, callback) {
  // It's actually a product-specific URL
  var namespace = 'https://example.com/claims/';

  context.accessToken[namespace + 'email'] = user.email;
  console.log(context.accessToken);
  console.log(user.email);
  return callback(null, user, context);
}

console.log() is for Real-time Webtask Logs.

When I tested this with “TRY THIS RULE” in individual Rules page, the debug console was outputting the values as expected. But when tried to “TRY ALL WITH…” in root Rules page and tried to login from the actual product, the value was not added.

I can get the accessToken itself, so I can get the email directly, but I want to get it at the same time if possible. Please help me out. Thanks!

Hi @u1f419,

Are you saying that when you login from your app the rule is not firing? That doesn’t make any sense.
Make sure you have the real time webtask logs on, log in from your app, and check the logs to see what is going on.

John

2 Likes

Why is it? I thought Rules was supposed to be triggered during the authentication process, login, etc., but when is it actually triggered?

The actual code uses auth0-react, which is retrieved by getAccessTokenSilently after loginWithRedirect.

Rules are scripts that are run upon successful login

I understand. If so, how can I include the email in the accessToken and get it?

Hi @u1f419,

What do the realtime webtask logs show? Put some debug statements in, run it, and then put both the rule and the log output here.

John

1 Like

Hey there!

As this topic is related to Rules - Hooks - Actions, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!