Cannot post to user app metadata after api call on post login flow

Hi,

I have a problem where i cannot post to user app metadata after api call in a post login flow. I get to call the api and log the users _id value, but it will not post it to the users app_metadata. Here is a image of my post login flow and its response after running.

Here is the response from the web console:

Commands:
[
  {
    "key": "mongoId",
    "target": "application",
    "type": "SetMetadata",
    "value": "63e55fa299112b14932a7ec9"
  }
]
Error:
{}
Logs:
63e55fa299112b14932a7ec9
{
  app_metadata: {},
  created_at: '2023-02-10T18:29:34.706Z',
  email: 'j+smith@example.com',
  email_verified: true,
  family_name: 'Smith',
  given_name: 'John',
  identities: [
    {
      accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gU21pdGgiLCJpYXQiOjE1MTYyMzkwMjJ9.Q_w2AVguPRU2KskCXwR7ZHl09TQXEntfEA8Jj2_Jyew',
      connection: 'Username-Password-Authentication',
      isSocial: false,
      profileData: {},
      provider: 'auth0',
      userId: '5f7c8ec7c33c6c004bbafe82',
      user_id: '5f7c8ec7c33c6c004bbafe82'
    }
  ],
  last_password_reset: '2023-02-10T18:29:34.706Z',
  multifactor: [],
  name: 'j+smith@example.com',
  nickname: 'j+smith',
  phone_number: '18882352699',
  phone_verified: false,
  picture: 'http://www.gravatar.com/avatar/?d=identicon',
  updated_at: '2023-02-10T18:29:34.706Z',
  user_id: 'auth0|5f7c8ec7c33c6c004bbafe82',
  user_metadata: {},
  username: 'jsmith'
}
Stats:
{
  "total_request_duration_ms": 205,
  "total_runtime_execution_duration_ms": 200,
  "runtime_processing_duration_ms": 4,
  "action_duration_ms": 158,
  "runtime_external_call_duration_ms": 38,
  "boot_duration_ms": 42,
  "network_duration_ms": 5
}

Hi there @ludvig.bergsaker welcome to the community!

Everything looks good to me here - Have you checked the actual user profile in the Auth0 dashboard and/or via the management API? I suspect the app_metadata is being added, it’s just not being logged.

Let us know if that’s not the case!

Hi, thanks for answering.
I have checked and it does not add it to the users metadata :confused:

Thanks for confirming! If you hard code a piece of metadata in your action to add using setAppMetadata does that get pushed to your user’s profile correcty?

@tyf Yep, if i hard code a value it works. But not with the response from my api

1 Like

Hey @ludvig.bergsaker thanks for confirming - Good to know the Action itself is working at least. I’ve set up a very similar Action with a dummy API and I’m able to get the ID and set it in app metadata without issue. If you go to your tenant settings → advanced → Extensibilty what version of Node are you running?

If you’d like to test my Action out, here it is:

exports.onExecutePostLogin = async (event, api) => {
  const axios = require('axios');
  const res = await axios.get('https://63ec312631ef61473b1e95c5.mockapi.io/api/v666/users')

  api.user.setAppMetadata("test_metadata", res.data[0].user_id)
};

This topic was automatically closed after 10 days. New replies are no longer allowed.