简体   繁体   English

beforeSave 不修改 request.object

[英]beforeSave doesn't modify request.object

I'm trying to add some additional attributes for new user through cloud code:我正在尝试通过云代码为新用户添加一些额外的属性:

Parse.Cloud.beforeSave(Parse.User, (request) => {
    if (!request.original) {
        // New user
        Parse.Config.get()
            .then((config) => {
                const ProfileIcon = Parse.Object.extend("ProfileIcon");
                const iconId = config.get("defaultProfileIcon");
                const user = request.object;
                // ...many user.set
                user.set("profileIcon", ProfileIcon.createWithoutData(iconId), {
                    useMasterKey: true,
                }); // Pointer
                // This will save as expected, but cause recursion
                // user.save({ useMasterKey: true });
            })
            .catch((err) => {
                console.error(err);
            });
    }
});

The code above triggered and executed without any error, but when I check the database, none of my custom attributes show up.上面的代码触发并执行没有任何错误,但是当我检查数据库时,没有显示我的自定义属性。 Passing the master key also does nothing.传递主密钥也没有任何作用。 How can I fix this?我怎样才能解决这个问题?
Or is it because the request from the client (Android, have no access to master key), if so then how can I set master key for the request, since Parse.Cloud.useMasterKey() is deprecated?或者是因为来自客户端的请求(Android,无法访问主密钥),如果是这样,那么我如何为请求设置主密钥,因为Parse.Cloud.useMasterKey()已被弃用?

Here, modifying object on save does not mention anything about return , but before save file does.在这里, 在保存时修改对象没有提到任何关于return ,但 在保存文件之前 So I thought I would give it a try, turns out it worked.所以我想我会试一试,结果它奏效了。 Still not sure if this is the right way though.仍然不确定这是否是正确的方法。

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

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