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

UpdateMetadata appears to fail silently. #272

Open
bnewland123 opened this issue Mar 1, 2024 · 5 comments
Open

UpdateMetadata appears to fail silently. #272

bnewland123 opened this issue Mar 1, 2024 · 5 comments

Comments

@bnewland123
Copy link

bnewland123 commented Mar 1, 2024

I'm testing updating user metadata with the SDK. The call appears to succeed with no error, but the user is not updated.
Is there something else that I'm missing here? I've also made sure the ID is the correct one.

privateStuff := map[string]interface{}{
	"pid": "<id>",
}
publicStuff := map[string]interface{}{
	"likes": "videogames",
}
unsafe := make(map[string]interface{})
privateBytes, err := json.Marshal(privateStuff)
if err != nil {
	log.Error(err)
	return nil, err
}
publicBytes, err := json.Marshal(publicStuff)
if err != nil {
	log.Error(err)
	return nil, err
}
unsafeBytes, err := json.Marshal(unsafe)
if err != nil {
	log.Error(err)
	return nil, err
}
log.Infof("Updating user with ID: %s", user.ID)
updatedUser, err := client.Users().UpdateMetadata(user.ID, &clerk.UpdateUserMetadata{
	PrivateMetadata: privateBytes,
	PublicMetadata:  publicBytes,
	UnsafeMetadata:  unsafeBytes,
})
@gkats
Copy link
Member

gkats commented Mar 2, 2024

Thanks for reporting @bnewland123. This is indeed a bug.

The issue is fixed in the v2 version of the Go SDK. https://github.com/clerk/clerk-sdk-go/tree/v2

We'll take a look into the problem and try to fix it for v1 as well.

@reginaldl
Copy link

reginaldl commented Mar 15, 2024

@gkats I have the same problem with v2:

        data, err := json.Marshal(publicMetadata)
        if err != nil {
                return err 
        }   
        rawMessage := json.RawMessage(data)
        u, err := user.UpdateMetadata(
                context.Background(),
                userId,
                &user.UpdateMetadataParams{
                        PublicMetadata: &rawMessage,
                },  
        )   
        log.Printf("%v", string(u.Response.RawJSON))
        return err 

Same behavior as described earlier, succeeds but won't update. Switching to user.Update works though.
Also, is v2 still in beta?

@reginaldl
Copy link

So it turns out to be a backend issue and X-Clerk-Sdk header, I can repro with the following curl command:

curl -vvv -X PATCH 'https://api.clerk.com/v1/users/<user_id>/metadata' \
-H 'Authorization: Bearer <secret>' \
-H 'Content-Type: application/json' \
-H 'User-Agent: clerk/clerk-sdk-go@v2.0.0' \
-H 'X-Clerk-Sdk: go/v2.0.0' \
-d '{"public_metadata":{"test":"ok"}}'

This won't work. Remove X-Clerk-Sdk header and it works.

@gkats
Copy link
Member

gkats commented Mar 19, 2024

Hello @reginaldl thank you for reporting. This was indeed a backend issue as you found out yourself.

The fix is now live.

Also, is v2 still in beta?

Yes, v2 is still in beta, at least officially. It's pretty stable though and we don't expect the APIs to change. The only thing that's missing is cookie-based authentication support.

@reginaldl
Copy link

Great! Thanks for the update. Let's close this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants