Verified Commit 411234ae authored by Frauke's avatar Frauke
Browse files

Add check on authentication header

parent f658168f
// Application hooks that run for every service
const logger = require('./hooks/logger');
const errors = require('@feathersjs/errors');
module.exports = {
before: {
all: [ logger(), context => {
if((!context.params.query.secret && (context.data && !context.data.secret)) || (context.data && context.data.secret && context.data.secret !== 'ethical-design') || (context.params.query.secret && context.params.query.secret !== 'ethical-design')) {
throw new errors.NotAuthenticated('Secret is not correct.')
}
} ],
all: [ logger() ],
find: [],
get: [],
create: [],
......
const errors = require('@feathersjs/errors');
module.exports = function (app) { // eslint-disable-line no-unused-vars
// Add your custom middleware here. Remember, that
// in Express the order matters
app.use(function(req, res, next) {
let secret = null
if(req.headers && req.headers.authorization) {
secret = req.headers.authorization.replace('Bearer ', '')
}
if(!secret || secret !== 'ethical-design') {
throw new errors.NotAuthenticated('Secret is not correct.')
}
next();
})
};
......@@ -19,8 +19,6 @@ class Service {
console.log('done')
})
.catch((err) => {
console.log(err)
console.log(data)
return new errors.Unavailable('Service unavailable. The domain check/registration service is unavailable.')
})
}, data.delay)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment