Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function MongoDBStrategy(dbUrl, apiKey, dbName, collection) {
this.dbUrl = dbUrl;
this.apiKey = apiKey;
this.dbName = dbName;
this.collection = collection;
this.baseUrl = this.dbUrl + '/databases/' + this.dbName + '/collections/' + collection + '/';
// Call the super constructor - passing in our user verification function
// We use the email field for the username
LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this));
// Serialize the user into a string (id) for storing in the session
passport.serializeUser(function(user, done) {
done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure
});
// Deserialize the user from a string (id) into a user (via a cll to the DB)
passport.deserializeUser(this.get.bind(this));
// We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo'));
this.name = MongoDBStrategy.name;
}
function MongoDBStrategy(dbUrl, apiKey, dbName, collection) {
this.dbUrl = dbUrl;
this.apiKey = apiKey;
this.dbName = dbName;
this.collection = collection;
this.baseUrl = this.dbUrl + '/' + this.dbName + '/collections/' + collection + '/';
// Call the super constructor - passing in our user verification function
// We use the email field for the username
LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this));
// Serialize the user into a string (id) for storing in the session
passport.serializeUser(function(user, done) {
done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure
});
// Deserialize the user from a string (id) into a user (via a cll to the DB)
passport.deserializeUser(this.get.bind(this));
// We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo'));
this.name = "mongo";
}