2015-12-29 12 views
9

कुछ ही घंटों अब, बहुत निराशा होती है के लिए इस पर काम कर रहा ...पासपोर्ट js लापता साख

router.post('/', 
passport.authenticate('local-signup', function(err, user, info) { 
    console.log(err); 
}), function(req, res){ 
    console.log(req); 
    res.setHeader('Content-Type', 'application/json'); 
    res.send(JSON.stringify({ a: 1 })); 
}); 

जब मैं इस चलाने के लिए, मैं console.log इस्तेमाल किया, उत्पादन { message: 'Missing credentials' } था, जो मुझे विश्वास है कि शरीर पार्सर शरीर के संदेश को सही ढंग से पार्स नहीं कर रहा है। जब मैं इस मार्ग हालांकि ...

router.post('/', 
    function(req, res){ 
     console.log(req.body); 
     res.setHeader('Content-Type', 'application/json'); 
     res.send(JSON.stringify({ a: 1 })); 
    }); 

जब मैं console.log इस्तेमाल किया उपयोग करते हैं, उत्पादन {password: 'password', email: '[email protected]'} था, जो इंगित करता है कि req.body चर ठीक से सेट किया जा रहा है और उपलब्ध हैं।

app.js

var express = require('express'); 
var app = express(); 
var routes = require("./config/routes.config"); 
var models = require("./config/models.config"); 
var session = require('express-session'); 
var bodyParser = require('body-parser'); 

models.forEach(function(model){ 
    GLOBAL[model] = require('./models/'+model+".model"); 
}); 
var passport = require("./config/passport.config"); 

app.use(bodyParser.urlencoded({ extended: true })); 
app.use(session({ secret: 'simpleExpressMVC', resave: true, saveUninitialized: true })); 
app.use(passport.initialize()); 
app.use(passport.session()); 
+0

मैं भी इस मुद्दे को एक ही प्रकार का सामना करना पड़ रहा हूँ और खोज के alots किया, लेकिन coundn't किसी भी समाधान खोजने के :-( –

उत्तर

24

मैं देख रहा हूँ अपने req.body{password: 'password', email: '[email protected]email.com'} शामिल हैं। email पासपोर्टज की तलाश नहीं है, लेकिन username है। आप या तो अपने एचटीएमएल/जेएस पर अपने इनपुट नाम बदल सकते हैं, या आप req.body में डिफ़ॉल्ट पैरामीटर पासपोर्टजेज़ को बदल सकते हैं। आपको इन परिवर्तनों को लागू करने की आवश्यकता है जहां आप अपनी रणनीति को परिभाषित करते हैं।

passport.use(new LocalStrategy({ // or whatever you want to use 
    usernameField: 'email', // define the parameter in req.body that passport can use as username and password 
    passwordField: 'password' 
    }, 
    function(username, password, done) { // depending on your strategy, you might not need this function ... 
    // ... 
    } 
)); 
2

Router.post में:

router.post('/', passport.authenticate('local-signup', { 
    successRedirect: '/dashboad', 
    failureRedirect: '/', 
    badRequestMessage: 'Your message you want to change.', //missing credentials 
    failureFlash: true 
}, function(req, res, next) { 
... 
संबंधित मुद्दे