mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 16:57:39 -05:00
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
/* Initializing PassportJS */
|
|
const User = require("../models/user");
|
|
const local = require("./passport-strategies/local");
|
|
|
|
module.exports = function (app, passport) {
|
|
// Configure Passport authenticated session persistence.
|
|
//
|
|
// In order to restore authentication state across HTTP requests, Passport needs
|
|
// to serialize users into and deserialize users out of the session. The
|
|
// typical implementation of this is as simple as supplying the user ID when
|
|
// serializing, and querying the user record by ID from the database when
|
|
// deserializing.
|
|
passport.serializeUser((user, done) => {
|
|
console.log("passport.serializeUser() - Serializing the user: " + user.id);
|
|
done(null, user.id)
|
|
})
|
|
|
|
passport.deserializeUser((id, done) => {
|
|
console.log("passport.deserializeUser() - Trying to deSerialize the user: " + id);
|
|
User.findById(id, (err, user) => {
|
|
console.log("passport.deserializeUser() - Found the user: " + user);
|
|
console.log("passport.deserializeUser() - Err: " + err);
|
|
done(err, user)
|
|
})
|
|
})
|
|
|
|
|
|
// use the following strategies
|
|
passport.use(local)
|
|
}
|
|
|