Use standard method for getting an objectId

This commit is contained in:
Jonathan Cremin 2015-09-02 19:29:39 +02:00
parent dbac3d7fe5
commit c6f0b16e5c

View file

@ -1,7 +1,5 @@
import passwords from 'passwords';
import auth from 'basic-auth';
import mongoSetup from 'mongodb-promisified';
const objectID = mongoSetup().objectID;
import debugname from 'debug';
const debug = debugname('hostr-api:auth');
@ -18,7 +16,7 @@ export default function* (next) {
const userToken = yield this.redis.get(this.req.headers.authorization.substr(1));
this.assert(userToken, 401, '{"error": {"message": "Invalid token.", "code": 606}}');
debug('Token found');
user = yield Users.findOne({'_id': objectID(userToken)});
user = yield Users.findOne({'_id': this.db.objectID(userToken)});
} else {
const authUser = auth(this);
this.assert(authUser, 401, badLoginMsg);