[英]How to sign up user and then keep them signed in and access current user Parse Server?
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. 我试图让用户注册,我有HTML表单工作等我只需要处理注册本身。
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. 用户已成功创建但我不确定如何保持用户登录或访问以Parse.User对象身份登录的当前用户。
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.
不知道该怎么做才能让他们登录并为当前用户访问Parse.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
另一种存储方式是数据库,另一种方式是
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
来检索用户类。
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 资料来源: http : //parseplatform.github.io/docs/js/guide/#setting-the-current-user
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.