useUser user_metadata undefined after user first sign's up

Hi @wfsmith

Welcome to the Auth0 Community!

Just to confirm, are you setting user metadata inside the PostLogin trigger, right?
Basically, if that is the case, the cause is the fact that the user profile is already generated and the user metadata is set after that, thus your application receiving a profile without the user metadata.

In the example below:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https:/my-cool-name-space";
  api.idToken.setCustomClaim(`${namespace}/meta`, "random_data");
  api.accessToken.setCustomClaim(`${namespace}/mtea`, "random_data");

  const metadata = "test_data";

  api.user.setUserMetadata("some_user_metadata", metadata);

  console.log(event.user.user_metadata);
};

If a user signs up, the metadata will not be available in the user profile but it will be visible inside the dashboard. However, the custom claims set will be accessible after a successful signup and might be more suitable for your use case.

An workaround for the issue that you are experiencing would be to perform a silent authentication once the user authenticates so that it returns the user profile containing the set metadata.

If you have any other question, let me know!

Kind Regards,
Nik