Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
"TypeError: passport.serialize is not a function" with Passport.js

I am relatively new to passport.js and have been following an online guide in conjunction with the documentation here: https://github.com/saintedlama/passport-local-mongoose. However, when I start my server in webstorm, I consistently get the error: TypeError: passport.serialize is not a function. I also saw this similar post: Passport.js .authenticate() throwing TypeError: undefined is not a function, but my problem is different from the one solved in that question. My relevant code is below:

user.js

var mongoose = require('mongoose'),
Schema = mongoose.Schema,
passportLocalMongoose = require('passport-local-mongoose');
var User = new Schema({
    username: String,
    password: String,
    studentID: String,
    grades: [{
        subject: String,
        grade: String
    }]
});
User.plugin(passportLocalMongoose);
module.exports = mongoose.model('User', User);

app.js

var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var routes = require('./routes/index');
var LocalStrategy = require('passport-local').Strategy;
var passport = require('passport');
var request = require('request');
var cheerio = require('cheerio');
var User = require('./models/user');

var app = express();
passport.initialize();
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serialize(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

All help is appreciated!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

There is no passport.serialize function. The correct is passport.serializeUser.

This is a code snipped from passport.

Authenticator.prototype.serializeUser = function(fn, req, done) {
...

and

Authenticator.prototype.deserializeUser = function(fn, req, done) {
...

I believe it is your problem.

Hope it can help.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!