javascript icon indicating copy to clipboard operation
javascript copied to clipboard

`publicMetadata` does not update within the member list object, it is always empty.

Open pavittarx opened this issue 2 years ago • 6 comments

Preliminary Checks

  • [X] I have reviewed the documentation: https://clerk.com/docs

  • [X] I have searched for existing issues: https://github.com/clerkinc/javascript/issues

  • [X] I have not already reached out to Clerk support via email or Discord (if you have, no need to open an issue here)

  • [X] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.

Reproduction / Replay Link

https://replit.com/@PavittarSingh1/ClerkBackendAPI-1

Publishable key

pk_test_aGVscGluZy1qYWd1YXItODguY2xlcmsuYWNjb3VudHMuZGV2JA

Description

Steps to reproduce:

  1. Update publicMetadata for any user.
  2. Fetch Individual user data, vs all the members of the organization.

Expected behavior: the member within the organization member list should have their publicMetadata updated.

Actual behavior:

  • publicMetadata is updated and correct when fetching individual user data.
  • publicMetadata is empty in organizationMembersList

image

image

image

Environment

I tried it locally + on replit, so this is more of a problem w/ SDK. 
Let me know, if any more information is needed. 
Thanks!

pavittarx avatar Oct 26 '23 18:10 pavittarx

You can quickly reproduce this by putting in your clerk secret key here, like this ... image

pavittarx avatar Oct 26 '23 19:10 pavittarx

Hey @pavittarx, seems like you are expecting to read from a OrganizationMembership's publicMetadata but you are populating a User's publicMetadata

panteliselef avatar Nov 07 '23 11:11 panteliselef

Yes, the api I am using lists the info about the members of the organization, which are technically users. So, this should have, publicMetadata & privateMetadata of the user. And then, if you see it has an organization key which again has organization's public and private meta data. :)

image

pavittarx avatar Nov 08 '23 05:11 pavittarx

Any update on this issue?

I have been told by the Clerk sales team that in order to avoid purchasing the 'Enhanced B2B SaaS add-on', which gives me custom roles and permissions, I can instead build it myself by storing a users role in their public metadata.

However the following two options do not work:

  1. Use the organization API to retrieve all members of the organisation, and view their public metadata. This does not work due to this issue, and the public metadata is always empty. (I have confirmed this in both the react and node SDKs).
  2. Use the users API to retrieve all users across all organisations, which does give me access to their public metadata, however the API does not include which organisations this user is a member of. This means I need to store the information of which organisations a user is a member of as part of their public metadata, something which is prone to many edge case errors, and the entire reason I have chosen Clerk is how organisations are a first class feature!

Edit: Looking into the source code, this seems not to be an issue with the SDK but the API. I have confirmed this by using the Clerk API Reference and can see the public metadata coming through as empty.

How do I go about raising this as an issue with the core API?

ryan-saffer avatar Mar 26 '24 23:03 ryan-saffer

As a workaround, we had to pass each member's userId to getUser to get their publicMetadata.

aliyeysides avatar May 23 '24 20:05 aliyeysides

I too am having this issue.

Attempting to retrieve a members publicMetadata is always empty. I am using the useOrganization hook to retrieve the list of members, then trying to access member.publicMetadata, and its always empty.

Example code: `const { isLoaded, memberships } = useOrganization(OrgMembersParams)

const members = memberships?.data?.filter( (member) => member.publicMetadata.someValue === true )`

In this case I was trying to filter out some users based on some data set in the public metadata. I believe the only way to do this is probably as aliyeysides says and perform an individual getUser call for each user, to get their public metadata.

If I console.log the publicMetadata its undefined. While in the clerk dashboard I can see my users have the metadata set. Mildly annoying and should definitely be fixed by now.

ryan-a-git avatar Oct 08 '24 04:10 ryan-a-git

Just wondering if there’s any update on this issue. It’s creating a significant bottleneck, especially with the publicMetadata showing differently in individual user data and organization member lists. Any info on a fix would be really helpful!

tencyle-nativs avatar Oct 28 '24 04:10 tencyle-nativs

We at Passionfroot are having the same issue. We know we have populated membership publicMetadata but when calling it via the session claims it always comes as empty. It is creating a significant bottleneck aswell to release a proper solution (multitenancy and memberships having an externalId`)

omarsotillo avatar Dec 30 '24 16:12 omarsotillo

We at Passionfroot are having the same issue. We know we have populated membership publicMetadata but when calling it via the session claims it always comes as empty. It is creating a significant bottleneck aswell to release a proper solution (multitenancy and memberships having an externalId`)

So I mostly worked out what is going on here I think, I will try to explain as best I can. Basically from my investigation there is undocumented behaviour here where the organization memberlist does not return the public user data since the object is a different object, not the proper user object.

I think the logic behind this is that the user in the organization should only return data relevant to that organization, not all of its public metadata. Since you could imagine if you use that to set say 'role:admin' in their metadata. Then switch orgs, the user may still have that role, in the wrong org.

There are a couple solutions, here, one of the best is probably to use a webhook to create the users locally in your own database and then you can easily store whatever you need without worrying about accessing the publicMetaData.

I think that how clerk has structured their queries is actually right in this case, it just would be great if they could put this information in the docs along with some code examples for work arounds.

ryan-a-git avatar Jan 02 '25 19:01 ryan-a-git

Same issue

y4qq avatar Mar 29 '25 13:03 y4qq