I know this question has been asked on here once before but I need to know if parse has done anything about it. My default user table has a pointer field to a UserProfile class. On signup I have this cloud code below.
Parse.Cloud.beforeSave(Parse.User,async (request)=>{
const user = request.object;
//Making a new Teacherprofile Class
const Objectextension = Parse.Object.extend("TeacherProfile");
const teacherProfile = new Objectextension();
teacherProfile.set("name", "harry");
//Putting teacher profile pointer
user.set("tProfile",teacherProfile);
});
This just dosent not work and results in a timeout.Is there anyway to create the userprofile on before save and associate it to the User Table ? Thanks
UPDATE
This is the working code.
Parse.Cloud.beforeSave(Parse.User,async (request)=>{
const user = request.object;
//if user id does not exists
//it is a new user
if (!user.id) {
//Making a new User Profile Object
const profileObject = Parse.Object.extend("TeacherProfile");
const teacherProfile = new profileObject();
teacherProfile.set("name", "harry");
await teacherProfile.save(null,{ useMasterKey: true });
//Putting teacher profile pointer in user
user.set("tProfile",teacherProfile);
}else{
console.log('old user');
}
});
After a bit more of experimentation I have come to the conclusion that before save is not at all advisable for User Profile Creation. When signing up lets say the username or email already exists , then the signup does not happen but the profile is saved regardlesss. So I would advice against it