I am trying to get a user to sign up, I have the HTML form working etc. I just need to handle the sign up itself.
The user is successfully created BUT I'm not sure how to keep the user logged in or access the current user logged in as a Parse.User object.
app.post("/sign-up", function (req, res) {
var userObject = new Parse.User();
userObject.set("username", username);
userObject.set("password", password);
userObject.set("email", email);
userObject.set("supportEmail", email);
userObject.signUp(null, {success: function(user) {
//success
res.redirect('/admin');
},
error: function(user, error) {
//show error
console.log(error.message);
res.render('sign-up', {success:false, errorMessage:error.message});
}
});
}); Not sure what to do in order to keep them logged in and to acess the Parse.User object for the current user.
you can save in global variable in your application. also you can export user object to use in other files. There is another way to store in database or one other way is to app.locals.user = userObject
var userObject = new Parse.User();
app.post("/sign-up", function (req, res) {
userObject.set("username", username);
userObject.set("password", password);
userObject.set("email", email);
userObject.set("supportEmail", email);
app.locals.user = userObject;
userObject.signUp(null, {success: function(user) {
//success
res.redirect('/admin');
},
error: function(user, error) {
//show error
console.log(error.message);
res.render('sign-up', {success:false, errorMessage:error.message});
}
});
module.exports.userObject = userObjetct;
The signup promise resolves in an authentication object along with the session token.
Then you can use it and call Parse.User.become
to retrieve the user class.
Parse.User.become("session-token-here").then(function (user) {
// The current user is now set to user.
}, function (error) {
// The token could not be validated.
});
Source: http://parseplatform.github.io/docs/js/guide/#setting-the-current-user
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.