MCPcopy Create free account
hub / github.com/angular-app/angular-app / MongoDBStrategy

Function MongoDBStrategy

server/lib/mongo-strategy.js:6–27  ·  view source on GitHub ↗
(dbUrl, apiKey, dbName, collection)

Source from the content-addressed store, hash-verified

4var rest = require('request');
5
6function MongoDBStrategy(dbUrl, apiKey, dbName, collection) {
7 this.dbUrl = dbUrl;
8 this.apiKey = apiKey;
9 this.dbName = dbName;
10 this.collection = collection;
11 this.baseUrl = this.dbUrl + '/databases/' + this.dbName + '/collections/' + collection + '/';
12
13 // Call the super constructor - passing in our user verification function
14 // We use the email field for the username
15 LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this));
16
17 // Serialize the user into a string (id) for storing in the session
18 passport.serializeUser(function(user, done) {
19 done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure
20 });
21
22 // Deserialize the user from a string (id) into a user (via a cll to the DB)
23 passport.deserializeUser(this.get.bind(this));
24
25 // We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo'));
26 this.name = MongoDBStrategy.name;
27}
28
29// MongoDBStrategy inherits from LocalStrategy
30util.inherits(MongoDBStrategy, LocalStrategy);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected