milan.dzeki
milan.dzeki

Reputation: 41

SUPABASE/JavsScript: how to DELETE user metadata?

Is there a way to delete user metadata in Supabase? They offer update() option, but it seems it works as patch request, so I can't find a way to delete it.

Here's their code:

```const { user, error } = await supabase.auth.update({ 
    data: { hello: 'world' } 
});```

I tried to do this:

```const { user, error } = await supabase.auth.update({ 
    data: {} 
});```

But is doesn't do anything. Can metadata be deleted? Thanks

Upvotes: 2

Views: 1096

Answers (1)

chipilov
chipilov

Reputation: 569

It is possible to set the metadata field to an empty JSON object (i.e. {}) but, currently, there is no way to set it to NULL. Also, you would need to know all the fields that are already stored in the metadata because you need to remove each one explicitly.

If this works for your scenario, the way to do it is to send a data object where each field that you want removed has a value of null.

For example, if you have the following JSON in your metadata: { 'field1': 2, 'field2': 'something' }, you can set the metadata to an empty JSON object like this:

supabase.auth.update({ 'data': { 'field1': null, 'field2': null } });

Upvotes: 1

Related Questions