setAppMetadata nested key

During the post-login action, I’d like to set an app metadata key/value pair. However, the key is nested (see below). “foo.bar” key is not accepted in this API as in (api.user.setAppMetadata(“foo.bar”, “123”)). What’s the recommended way of doing it?
“app_metadata”: {
“foo”: {
“bar”: “123”,
}
}

Hi @ak_ee

Welcome to the Auth0 Community! It’s great to have you here :slight_smile:

I understand you need to be able to set nested key values pairs like in your example. Something like the below will get this to work for you.

exports.onExecutePostLogin = async (event, api) => {
  var data = {bar:"123"};

  api.user.setUserMetadata('foo', data);
};

This will produce the output:

{
  "foo": {
    "bar": "123"
  }
}

All the best and have a great rest of your day.

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.