简体   繁体   English

SUPABASE/JavsScript:如何删除用户元数据?

[英]SUPABASE/JavsScript: how to DELETE user metadata?

Is there a way to delete user metadata in Supabase?有没有办法删除 Supabase 中的用户元数据? They offer update() option, but it seems it works as patch request, so I can't find a way to delete it.他们提供 update() 选项,但它似乎作为补丁请求工作,所以我找不到删除它的方法。

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谢谢

It is possible to set the metadata field to an empty JSON object (ie {} ) but, currently, there is no way to set it to NULL .可以将元数据字段设置为空 JSON object (即{} ),但目前无法将其设置为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 .如果这适用于您的方案,则方法是发送数据 object,其中您要删除的每个字段的值为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:例如,如果您的元数据中包含以下 JSON: { 'field1': 2, 'field2': 'something' } ,您可以将元数据设置为空 JSON object,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM