注册后自动登录

时间:2016-11-27 02:04:57

标签: node.js express feathersjs

我正在尝试创建帐户后自动登录用户。 需要将它们重定向到/auth/local/发送他刚刚创建的用户和密码。

这是我的middleware/signup.js

'use strict';

module.exports = function(app) {
return function(req, res, next) {
const body = req.body;

// Get the user service and `create` a new user
app.service('users').create({
  email: body.email,
  password: body.password
})
// Then redirect to the login page
.then(user => app.post('/auth/local', function(req, res){
   req.body(user);
}))
// On errors, just call our error middleware
.catch(next);
 };
};

这不会给出任何错误......创建用户后只需一次永久加载。 帮助

1 个答案:

答案 0 :(得分:0)

首先,这是一个永恒的加载,因为您没有发送回复或致电next。请阅读about express middlewares here

除此之外,您为什么要从自己的API发出POST请求?我在这里没有足够的关于app的内容,但是你的代码看起来更像是一个路由定义,而不是像请求一样。 在这里你应该有一些方法来调用一个验证用户身份的函数。 例如,如果使用护照:

'use strict';

module.exports = function(app) {
return function(req, res, next) {
const body = req.body;

// Get the user service and `create` a new user
app.service('users').create({
  email: body.email,
  password: body.password
})
// Then redirect to the login page
.then(user => passport.authenticate('local')(req, res, next))
// On errors, just call our error middleware
.catch(next);
 };
};