Parse.object is not a constructor

im trying to add row to follow table
which takes user(pointer) and follows(pointer) and status(String) all are required field

CODE:
QueryBuilder follows =
QueryBuilder(ParseUser.forQuery());
follows.whereEqualTo(“username”, “jathin”);
var res = await follows.query();

  if (res.success) {
    ParseUser? user = await ParseUser.currentUser();
    inspect(user);
    ParseObject followsave = ParseObject("Follow");
    followsave.set("user", user);
    followsave.set("follows", res.result[0]);
    followsave.set("status", "following");
    var result = await followsave.save();
    inspect(result);
  }

output:

I/flutter (18407):
I/flutter (18407): ╭-- Parse Request
I/flutter (18407): curl -X POST -H ‘content-type: text/plain; charset=utf-8’ -H ‘user-agent: Flutter Parse SDK 3.1.0’ -H ‘X-Parse-Application-Id: ap-id’ -H ‘X-Parse-Session-Token: r:92d353396e32c5461e658a8642cb1e4d’ -H ‘X-Parse-Client-Key: client-key’ -d ‘{“user”:{"__type":“Pointer”,“className”:"_User",“objectId”:“nABM5alZkZ”},“follows”:{"__type":“Pointer”,“className”:"_User",“objectId”:“gBz5eCTBia”},“status”:“following”}’ https://parseapi.back4app.com/classes/Follow
I/flutter (18407):
I/flutter (18407): https://parseapi.back4app.com/classes/Follow
I/flutter (18407): ╰–
I/flutter (18407): ╭-- Parse Response
I/flutter (18407): Class: Follow
I/flutter (18407): Function: ParseApiRQ.create
I/flutter (18407): Status Code: 141
I/flutter (18407): Type: ScriptError
I/flutter (18407): Error: Parse.object is not a constructor
I/flutter (18407): ╰–
I/flutter (18407):

Perminsion for both users is public read write and authunticated read write enabled
Current user is also not null and i have logged in

but Server System Log says
[2021-07-05T17:58:18.581Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:58:18.580Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:57:33.706Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:57:33.690Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:56:03.444Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:56:03.443Z]
Got an error 101 : Permission denied, user needs to be authenticated.

[2021-07-05T17:55:51.142Z]
Got an error 101 : Permission denied, user needs to be authenticated.

im new to parse please help.

Do you have any trigger in place for this class Follow?

1 Like

thank you for ur response.
yes i have is this wrong to do like this, if it is how should i do it?

thanks in advance :slight_smile:

what im trying to achive is,

  1. i have table Notification with to(Pointer to User) and from(Pointer to User).
  2. i have Follow table with user(Pointer to User) and follows(Pointer to User).
  3. User table with followers count and following count

I’m trying to add row to Follow Table using code and it adds properly but after executing beforeSave it send verification email to use and sets email veririfed false.

QueryBuilder<ParseUser> follows =
          QueryBuilder<ParseUser>(ParseUser.forQuery());
      follows.whereEqualTo("username", "jathin");
      var res = await follows.query();

      if (res.success) {
        ParseUser? user = await ParseUser.currentUser();
        inspect(user);
        ParseObject followsave = new ParseObject("Follow");
        followsave.set("user", user);
        followsave.set("follows", res.result[0]);
        followsave.set("status", "following");
        var result = await followsave.save();
        inspect(result);
      }

then when i save this i trying to create notification and increment followers and following count respectively using cloud code function below:

PROBLEM: every time i try to add row follow table then follows user that is ‘jathin’ in this case he is getting verification mail and his email verified is set to false

Im total new to parse im coming from Firebase please help.

Parse.Cloud.beforeSave("Follow", async (request) => {
    const status = request.object.get("status");
    var followsname = "";
    var _username = "";
    if (!request.original) {
        if (status == "following") {
            const following = new Parse.Query(Parse.User);
            following.get(request.object.get("user").id)
                .then(function (user) {
                    const jsondata = JSON.stringify(user);
                    const userjson = JSON.parse(jsondata);
                    user.increment("following");
                    _username = userjson.username;
                    console.log(_username);
                    user.save(null, { useMasterKey: true });
                })
                .catch(function (error) {
                    console.error("Got an error in following" + error.code + " : " + error.message);
                });
            const follower = new Parse.Query(Parse.User);
            await follower.get(request.object.get("follows").id)
                .then(function (user) {
                    const jsondata = JSON.stringify(user);
                    const userjson = JSON.parse(jsondata);
                    user.increment("followers");
                    followsname = userjson.username;
                    //return was here
                    user.save(null, { useMasterKey: true });
                })
                .catch(function (error) {
                    console.error("Got an error in follows save" + error.code + " : " + error.message);
                });
            const notification = new Parse.Object("Notification");
            notification.set("from", request.object.get("user"));
            notification.set("to", request.object.get("follows"));
            notification.set("type", "following");
            notification.set("priority", 1);
            notification.set("read", false);
            notification.set("data", _username + " started following you.");
            try {
                const result = await notification.save(null, { useMasterKey: true });
                console.log('Notification created', result);
                request.object.set("notification", notification);
            } catch (error) {
                console.error('Error while creating Notification: ', error);
            }


        } else if (status == "requested") {
            const follower = new Parse.Query(Parse.User);
            await follower.get(request.object.get("user").id)
                .then(function (user) {
                    const jsondata = JSON.stringify(user);
                    const userjson = JSON.parse(jsondata);
                    _username = userjson.username;
                  
                })
                .catch(function (error) {
                    console.error("Got an error in follows save" + error.code + " : " + error.message);
                });
            const notification = new Parse.Object("Notification");
            notification.set("from", request.object.get("user"));
            notification.set("to", request.object.get("follows"));
            notification.set("type", "request");
            notification.set("priority", 1);
            notification.set("read", false);
            notification.set("data", _username + " has requested to following you.");

            try {
                const result = await notification.save(null, { useMasterKey: true });
                // Access the Parse Object attributes using the .GET method
                console.log('Notification created', result);
                request.object.set("notification", notification);
            } catch (error) {
                console.error('Error while creating Notification: ', error);
            }

        }
    } else {
        if (request.original.get("status") == "requested" && request.object.get("status") == "following") {
            const following = new Parse.Query(Parse.User);
            following.get(request.object.get("user").id)
                .then(function (user) {
                    user.increment("following");
                    //return was here
                    user.save();
                })
                .catch(function (error) {
                    console.error("Got an error " + error.code + " : " + error.message);
                });
            const follower = new Parse.Query(Parse.User);
            follower.get(request.object.get("follows").id)
                .then(function (user) {
                    user.increment("followers");
                    //return was here
                    user.save();
                })
                .catch(function (error) {
                    console.error("Got an error " + error.code + " : " + error.message);
                });
            const notification_user = new Parse.Object("Notification");
            notification_user.set("to", request.object.get("user"));
            notification_user.set("from", request.object.get("follows"));
            notification_user.set("type", "request");
            notification_user.set("priority", 1);
            notification_user.set("read", false);
            notification_user.set("data", request.object.get("follows").username + " has accepted following request.");
            try {
                const result = await notification_user.save(null, { useMasterKey: true });
                // Access the Parse Object attributes using the .GET method
                console.log('Notification created', result);

            } catch (error) {
                console.error('Error while creating Notification: ', error);
            }
            const notification_follower = new Parse.Object("Notification");
            notification_follower.set("from", request.object.get("user"));
            notification_follower.set("to", request.object.get("follows"));
            notification_follower.set("type", "request");
            notification_follower.set("priority", 1);
            notification_follower.set("read", false);
            notification_follower.set("data", request.object.get("user").username + " has started following you.");
            try {
                const result = await notification_follower.save(null, { useMasterKey: true });
                // Access the Parse Object attributes using the .GET method
                console.log('Notification created', result);

            } catch (error) {
                console.error('Error while creating Notification: ', error);
            }
        }
    }
}
);

is my method to save followers wrong? what im doing wrong

Have you seen my message at stack overflow ? I guess it is something related to this inspect function. Could you please share the code for this function?

i saw now but im not changing any email and its not problem with current user, this only happend when i tried to increment other user followers count in User tabel so now i created another tabel as Publicuserdata to store followers,following and post counts seems to be no problem.

Thank you for your help sir :slight_smile: