I get this error cant set headers after they are sent

1

Hello people, I am using passport-local and what I want to do is show the user when he / she does the login

My code is this

var passport = require('passport');
var localStrategy = require('passport-local').Strategy;
var User=require("../model/usuario"); 
	  
	

 var local = function (app) {

passport.use(new localStrategy({
			usernameField: 'username',
			passwordField: 'password',
			
		},
		function (username, password,done) {
				User.findOne({username: username})
			.then(function (user) {
				if (!user) return done(null, false, {message: 'El username ${username} no existe!'});
				if (user.password === password) {
					
					
					return done(null, user);


				} else {
					return done(null, false, {message: 'El password es incorrecto'});
				}
			});
		
		}
	));

	app.post('/regis', passport.authenticate('local', {



				successRedirect: '/extra',
				failureRedirect: '/regis/',
				failureFlash: true,
				
				
	}));


};

module.exports = local;

.....

var usuario=require("../model/user");
var useri=require("../model/usuario");


function usuariosguardados(app,io){

app.route("/salir")
.get((req,res)=>{
req.logout();
            res.redirect('/');
})


app.route("/extra")
.get((req,res)=>{

	useri.findOne({username:req.user.username},(err,user)=>{
if(user){
	res.render("extra",{user:user})
}
})




usuario.findOne({id_social:req.user.id},(err,user)=>{
if(user){
	res.redirect("/")
}else{
res.render("extra");
}

})


})

.post(function(req,res){
	if(req.user.provider=="facebook"){
var user=new usuario({
id_social:req.user.id,
userred:req.user._json.name,
username:req.body.username,
email:req.body.email,
foto:"http://graph.facebook.com/" + req.user.id + "/picture"

})

user.save(function(err){
if(err){
	console.log(err);
return
}})

}

  res.redirect('/');

})


app.route("/registroo")

.get((req,res)=>{
res.render("registroo")

})

.post(function(req,res){

	
	var usera = new useri({
			username: req.body.username,
			password: req.body.password
		});
		usera.save(function (err) {
			if (!err) {
return res.redirect('/regis');
}else{
	console.log(err);
}
		})

})
app.route("/regis")
.get(function(req,res){
	let error_message = req.flash('error')[0];
		res.locals.error_message = error_message;
res.render("regis")
})



}

module.exports=usuariosguardados

What I want to do is show the user that works but in doing that I get the error that and the css does not work or the js

this is what appears to me

    
asked by Matias Js 21.05.2017 в 01:40
source

1 answer

0

, First of all, require () is not part of the Javascript standard, it is built in Node .JS to load the modules, which would be something similar like adding script tags in your HTML code.

If it tells you that it is not defined, something tells me that you do not have the structure of your project configured in Node.JS or you have typo error in an imported module .

I recommend you take a look at the answer to this question - Uncaught ReferenceError: require is not defined , which will help you much more in understanding how to make the right decisions in controlling your scripts with Node.JS

Greetings!

    
answered by 21.05.2017 в 14:41