Help Needed: I am encountering this error and unable to resolve it. Can someone please check it out?
TypeError: res.end is not a function
at allFailed (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport\lib\middleware\authenticate.js:174:11)
at attempt (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport\lib\middleware\authenticate.js:180:28)
at Strategy.strategy.fail (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport\lib\middleware\authenticate.js:302:9)
at Strategy.authenticate (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport-local\lib\strategy.js:75:17)
at attempt (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport\lib\middleware\authenticate.js:366:16)
at authenticate (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport\lib\middleware\authenticate.js:367:7)
at C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\app.js:70:37
at C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_modules\passport-local-mongoose\index.js:247:28
at processTicksAndRejections (internal/process/task_queues.js:97:5)
// If anyone can review the register route, that would be much appreciated.
require('dotenv').config();
const bodyParser = require("body-parser");
const express = require("express");
const ejs = require("ejs");
const mongoose = require("mongoose");
const session = require("express-session");
const passport = require ("passport");
const passportLocalMongoose = require("passport-local-mongoose");
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));
app.set("view engine","ejs");
app.use(session({
secret : "thisIsMyLitlleSecret",
resave : false,
saveUninitialized : false
}));
app.use(passport.initialize());
app.use(passport.session());
console.log(process.env.API_KEY);
mongoose.connect("mongodb://localhost:27017/userDB" , { useNewUrlParser: true , useUnifiedTopology: true });
mongoose.set("useCreateIndex", true);
const userSchema = new mongoose.Schema({
email : String,
password : String
});
userSchema.plugin(passportLocalMongoose);
const User = mongoose.model("User",userSchema);
passport.use(User.createStrategy());
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.get("/", function(req,res){
res.render("home");
});
app.get("/login", function(req,res){
res.render("login");
});
app.get("/secrets", function(req,res){
if(req.isAauthenticated){
res.render("secrets");
}
else{
res.redirect("/login")
}
})
app.get("/register", function(req,res){
res.render("register");
});
app.post("/register", function(req,res){
User.register({username : req.body.username}, req.body.password, function(err, user){
if(err){
console.log(err);
res.redirect("/register");
}
else
passport.authenticate("local")(res,req,function(){
res.redirect("/secrets");
});
});
});
app.post("/login",function(req,res){
});
app.listen(3000,function(req,res){
console.log("Server running on port 3000!!");
});
// Seeking suggestions on how to solve this issue.