feat(auth): migrate Application model from MongoDB to MySQL
- Add Sequelize migration creating the 'application' table
- Add Application Sequelize model with slugify, toJSONFor, toAuthJSON
- Rewrite passport-headerapikey strategy to use DB.Application
- Rewrite applications.routes.js to use Sequelize (findAll, count,
build/save, destroy) instead of Mongoose
- Fix pre-existing bug: passport was querying { encryptedKey } but the
stored field is named 'apikey'
- Add Application to MySQL models index and relationships
- Remove Application from Mongoose models index and delete the schema
This commit is contained in:
@@ -2,9 +2,7 @@ var secret = require('.').secret,
|
||||
bcrypt = require('bcrypt');
|
||||
const passport = require('passport');
|
||||
var HeaderAPIKeyStrategy = require('passport-headerapikey').HeaderAPIKeyStrategy;
|
||||
var mongoose = require('mongoose');
|
||||
var Application = mongoose.model('Application');
|
||||
|
||||
const DB = require('../database/mysql');
|
||||
|
||||
passport.use('headerapikey', new HeaderAPIKeyStrategy(
|
||||
{ header: 'Authorization', prefix: `${process.env.AUTHORIZATION_PREFIX} ` },
|
||||
@@ -12,13 +10,13 @@ passport.use('headerapikey', new HeaderAPIKeyStrategy(
|
||||
function (apikey, done) {
|
||||
const salt = secret;
|
||||
Promise.resolve(bcrypt.hash(apikey, salt)).then(function (encryptedKey) {
|
||||
Application.findOne({ encryptedKey: encryptedKey })
|
||||
DB.Application.findOne({ where: { apikey: encryptedKey } })
|
||||
.then(function (application) {
|
||||
if (!application) {
|
||||
return done({message: "Application can't be found.", status: 404}, false, false);
|
||||
return done({ message: "Application can't be found.", status: 404 }, false, false);
|
||||
}
|
||||
return done(null, application);
|
||||
});
|
||||
});
|
||||
}).catch(done);
|
||||
}
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user