Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of the field provider is mismatching in the bodyParameters for link method in user management apis #963

Open
4 of 5 tasks
ghost opened this issue Nov 1, 2023 · 4 comments
Labels
bug This points to a verified bug in the code

Comments

@ghost
Copy link

ghost commented Nov 1, 2023

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

The field provider is defined as string in the interfaces UserIdentities and GetUsers200ResponseOneOfInnerIdentitiesInner. But for the method link in users section of the management api client, the optional field provider in the bodyParameters of type PostIdentitiesRequest is defined as PostIdentitiesRequestProviderEnum. Due to this, one can't simply extract identitites from a user profile and loop it to link as suggested in the documentation, Since it throws a type mismatch error for provider.

Reproduction

The scenario is finding every account with same email id and linking it together.

Additional context

No response

node-auth0 version

4.0.1

Node.js version

18

@ghost ghost added the bug This points to a verified bug in the code label Nov 1, 2023
@adamjmcgrath
Copy link
Contributor

Hi @misuvii - thanks for raising this

Due to this, one can't simply extract identitites from a user profile and loop it to link as suggested in the documentation, Since it throws a type mismatch error for provider.

Could you share the code that raises the error? (and a link to the documentation)

@ghost
Copy link
Author

ghost commented Nov 7, 2023

@adamjmcgrath This is the code that raises the error

  const mergeMetadataAndLinkUsersTask = async (
    secondary: GetUsers200ResponseOneOfInner,
    identity: GetUsers200ResponseOneOfInnerIdentitiesInner,
  ) => {
    // Include user & app metadata
    const mergedUserMetadata = merge({}, secondary.user_metadata, primary.user_metadata);
    const mergedAppMetadata = merge({}, secondary.app_metadata, primary.app_metadata);

    const updateUserTask = async () => {
      await client.users.update(
        { id: primary.user_id! },
        {
          user_metadata: mergedUserMetadata,
          app_metadata: mergedAppMetadata,
        },
      );
    };

    const linkUsersTask = async () => {
      await client.users.link(
        { id: primary.user_id! },
        {
          user_id: secondary.user_id!,
          provider: identity.provider, // Here identity.provider is a string, but the method expects it to be of type PostIdentitiesRequestProviderEnum
        },
      );
    };

    await Promise.all([updateUserTask(), linkUsersTask()]);
  };```

@adamjmcgrath
Copy link
Contributor

Thanks for clarifying @misuvii - I've raised this with the team that owns those endpoints, will see if we can get this changed.

In the meantime, you can safely cast the identity.provider property as PostIdentitiesRequestProviderEnum

const linkUsersTask = async () => {
  await client.users.link(
    { id: primary.user_id! },
    {
      user_id: secondary.user_id!,
      provider: identity.provider as PostIdentitiesRequestProviderEnum,
    }
  );
};

@cbeardsmore
Copy link

Also hit this issue today, will use typecasting to bypass for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

No branches or pull requests

2 participants