0
내 백엔드 (node.js) 앱에 passport.js를 사용하여 사용자를 등록합니다. 항상 다음과 같은 오류가 발생합니다.위치 오류가있는 Json
ERROR SyntaxError: Unexpected token < in JSON at position 0 at Object.parse() at Response.webpackJsonp.../../../http/@angular/http.es5.js.Body.json (http.es5.js:797) at MapSubscriber.project (signup.component.ts:31)
새로 고침을 한 후 사이트에 가입했습니다. 내 코드에 어떤 문제가 있습니까?
signUp() {
this.userNotExist = "";
this.userExist="";
this.http.post('/signup',this.signform.value).map((res: any) => res.json())
.subscribe((res: any) => {
console.log('TTTTTTTTT')
console.log(res)
console.log('TTTTTTTTT')
if(res=='EXIST'){
this.userNotExist = "";
this.userExist = 'The email already exists';
}else {
this.userExist = "";
this.userNotExist = 'Congrats! You are now signed up';
window.location.reload();
}
}
),(error: any) => {
console.log(error);
}
}
내 Node.js를 응용 프로그램 : 당신은 대신 JSON
응답 xml
반응을 얻고있다
passport.use('local-signup', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'email',
passwordField : 'password',
nameMainField : 'nameMain',
firstNameField: 'firstName',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done) {
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
User.findOne({ 'local.email' : email }).lean().exec(function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);
// check to see if theres already a user with that email
if (user) {
return done(null, false, req.flash('signupMessage', 'Email already exists.'));
} else {
var newUserS = new User();
// set the user's local credentials
newUserS.local.email = email;
newUserS.local.password = newUserS.generateHash(password); // use the generateHash function in our user model
newUserS.local.nameMain = req.body.firstName + ' ' + req.body.nameMain;
newUserS.local.firstName = req.body.firstName;
newUserS.role=0;
newUserS.profileImage='/assets/fonts/male.png';
// save the user
newUserS.save(function(err, u) {
if (err)
throw err;
return done(null, newUserS);
});
}
});
}));
나는 MongoDB Mongoose를 사용하여 데이터를 검색하기 때문에 그렇게 생각하지 않는다. –
네트워크를 확인하십시오. 응답을 JSON에 매핑하는 동안 map ((res : any) => res.json())에서 오류가 발생합니다. 당신은 확실히 XML 응답을 받고 있습니다. – omeralper
좋습니다. 입술 만 작동 –