使用护照登录时出现POST 400(错误请求)错误

时间:2019-01-05 18:21:20

标签: node.js ajax express passport.js

编辑

我发现,这与需要密码或自定义验证功能的本地护照有关。我想走验证路线,但是由于我目前在项目中的时间限制,我将放弃使用标准密码方法。

================================================ ==

我正在为我的网站创建登录并尝试登录或注册时遇到奇怪的错误400错误,这似乎发生在我的signin-api-routes文件中的重定向路由中,完全交给护照或/ api / signin路由。

服务器端js

        $.post("/api/signup", {
        name: name,
        age: age,
        userLat: myLat,
        userLong: myLong
    }).then(function (data) {
        console.log("this ran1")
        window.location.replace(data);
    }).catch(function (err) {
        console.log(err);
    });

我的signin-api-routes片段

app.post("/api/signin", passport.authenticate("local"), function(req, res) {
console.log("err here3")
res.json("/home");
});

app.post("/api/signup", function(req, res) {
console.log(req.body);
db.User.create({
  name: req.body.name,
  age: req.body.age,
  userLat: req.body.userLat,
  userLong: req.body.userLong
}).then(function() {
  console.log("err here1")
  res.redirect(307, "/api/signin");
  console.log("err here2")
}).catch(function(err) {
  console.log(err);
  res.json(err);
});
});

我的password.js

 var passport = require("passport");
 var LocalStrategy = require("passport-local").Strategy;

 var db = require("../models");

passport.use(new LocalStrategy(
// Our user will sign in using name and age, rather than a "username"
{
usernameField: "name",
userageField: "age"
},
function(name, age, done) {
console.log("err here2.5");
// When a user tries to sign in this code runs
db.User.findOne({
  where: {
    name: name,
    age: age
  }
 }).then(function(dbUser) {
  // If there's no user with the given age and name
  if (!dbUser) {
    return done(null, false, {
      message: "Incorrect age or name."
    });
  }
  return done(null, dbUser);
});
}
));

passport.serializeUser(function(user, cb) {
cb(null, user);
});
passport.deserializeUser(function(obj, cb) {
cb(null, obj);
});

// Exporting our configured passport
module.exports = passport;

我用signin-api路由中的console.logs运行此命令,这要尽可能远,直到终端在浏览器中出现400错误之前

====================================

在PORT 8080上监听应用程序 执行(预设):插入UsersidnameageuserLatuserLongcreatedAt,{ {1}})值(DEFAULT,'PublicAPI','27',28.4031947,-80.6673939,'2019-01-05 17:47:23','2019-01-05 17:47:23'); < / p>

err here1

err here2

但运行时另一个有效的示例如下:

===================================

==>正在侦听端口8080。在浏览器中访问http://localhost:8080/。 执行(默认):插入updatedAtUsersidemailpasswordcreatedAt)值(DEFAULT,'dfdasrr @ gimaed.com','$ 2om','$ 2a $ 10 $ YubDrL1S9YNy2XM7IPbOneuowu8aTz6AQ1qJAhKooyJdCv.7YAteG','2019-01-05 07:47:47','2019-01-05 07:47:47');

err here1

err here2

err here2.5

执行(默认):从updatedAtid选择emailpasswordcreatedAtupdatedAtUsers UserUser ='dfda ='dfdasrr@gimaed.com';

err here3

他们哈希了他们不需要我的密码。

0 个答案:

没有答案