-
-
Save joeljuca/a4ee6a0b75a6d60e200500053efae90c to your computer and use it in GitHub Desktop.
PASSPORT & express-session config e models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const passport = require("passport"); | |
const { LocalStrategy } = require("passport-local"); | |
const User = require("./models/user"); | |
const Employee = require("./models/employee"); | |
const session = require('express-session'); | |
passport.use(new LocalStrategy(username, password, done) => { | |
User.findOne({ username }) | |
.then(user => done(null, user && User.isPasswordValid(user, password) ? user : false)) | |
.then(err => done(err)) | |
}); | |
passport.serializeUser((user, cb) => cb(null, user.id)); | |
passport.deserializeUser((id, cb) => User.findById(id, (err, user) => err ? cb(err) : cb(null, user))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require("mongoose"); | |
var passportLocalMongoose = require("passport-local-mongoose"); | |
var EmployeeSchema = new mongoose.Schema({ | |
username:String, | |
password:String, | |
firstname:String, | |
lastname:String, | |
birth:String, | |
adress:String, | |
role:String, | |
education:String, | |
experience:String | |
}) | |
EmployeeSchema.plugin(passportLocalMongoose); | |
module.exports = mongoose.model("Employee", EmployeeSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require("mongoose"); | |
var passportLocalMongoose = require("passport-local-mongoose"); | |
var UserSchema = new mongoose.Schema({ | |
username:String, | |
password:String, | |
isAdmin: {type:Boolean, default:false} | |
}) | |
UserSchema.plugin(passportLocalMongoose); | |
module.exports = mongoose.model("User", UserSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment