dgdgproto/app/Authenticator.js
2020-03-25 03:54:31 +01:00

30 lines
629 B
JavaScript

const bcrypt = require('bcryptjs');
class Authenticator {
constructor(database) {
this.database = database;
};
getAuthenticatedUser(req, callback) {
if (req.session.userId) {
let collection = this.database.collection('users');
collection.findOne({ id: req.session.userId }, {}, function (dbErr, dbRes) {
if (dbErr === null) {
if (dbRes === null) {
callback(null);
} else {
callback(dbRes);
}
} else {
callback(null);
}
});
} else {
callback(null);
}
};
};
module.exports = Authenticator;