简体   繁体   中英

In parse.com js SDK using .signUp logout the current user

I want to achieve the feature where and admin using a paga can create users. To achieve this I'm using .signUp function, everything works fine except for the fact that instead of using the callback success, upon creation of the user Parse logout the current user.

the code is the following

 // Create a new announcement with specified title and body. exports.create = function(req, res) { var user = new Parse.User(); res.locals.path = req.path; // Explicitly specify which fields to save to prevent bad input data userData = req.body; if(userData.email != "undefined"){ user.set("username", userData.email); } if(userData.name != "undefined"){ user.set("name", userData.name); } if(userData.surname != "undefined"){ user.set("surname", userData.surname); } if(userData.password != "undefined"){ user.set("password", userData.password); } if(userData.courses){ if(userData.courses != "undefined"){ var courses = new Array(); courses = userData.courses.split(","); user.set("courses", courses); } } if(userData.date != "undefined"){ user.set("birthday", userData.date); } if(userData.email != "undefined"){ user.set("email", userData.email); } if(userData.admin != "undefined"){ if(userData.admin == "on"){ user.set("admin", true); }else{ user.set("admin", false); } } if(userData.contact != "undefined"){ user.set("contact", userData.contact); } user.signUp(null, { success: function(user) { res.redirect('/users'); }, error: function(user, error) { // Show the error message somewhere and let the user try again. res.send(500, "Error: " + error.code + " " + error.message); } }); }; // Create a new tender with specified title and body. // Update a post based on specified id, title and body. exports.update = function(req, res) { var user = new User(); res.locals.path = req.path; if(req.params.id){ user.id = req.params.id; } userData = req.body; if(userData.name != "undefined"){ user.set("name", userData.name); } if(userData.surname != "undefined"){ user.set("surname", userData.surname); } if(userData.password != "undefined"){ user.set("password", userData.password); } if(userData.courses != "undefined"){ user.set("courses", userData.courses); } if(userData.date != "undefined"){ user.set("birthday", userData.date); } if(userData.email != "undefined"){ user.set("email", userData.email); } if(userData.email != "undefined"){ user.set("username", userData.email); } if(userData.admin != "undefined"){ if(userData.admin == "on"){ user.set("admin", true); }else{ user.set("admin", false); } } if(userData.contact != "undefined"){ user.set("contact", userData.contact); } Parse.Cloud.useMasterKey(); user.save().then(function() { res.redirect('/users'); }, function(err) { res.send(500, 'Failed saving user'); }); }; 

Is this a feature of Parse? Is there any way to avoid the logout of the current user?

The signUP method will replace your current user and logs you in as the new user. To avoid your admin user being logged out, you need to move this to a custom cloud function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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