feathers-auth-manager issue #74
const { authenticate } = require('feathers-authentication').hooks;
const verifyHooks = require('feathers-authentication-management').hooks;
const {
iff,
isProvider,
preventChanges,
} = require('feathers-hooks-common');
const sendVerificationEmail = require('../../hooks/sendVerificationEmail');
module.exports = {
before: {
create: [
verifyHooks.addVerification(),
],
},
after: {
create: [
sendVerificationEmail(),
verifyHooks.removeVerification(),
],
},
error: {}
};
{
"feathers": "^2.2.0",
"feathers-authentication": "^1.2.7",
"feathers-authentication-hooks": "^0.1.4",
"feathers-authentication-jwt": "^0.3.2",
"feathers-authentication-local": "^0.4.4",
"feathers-authentication-management": "^1.0.0",
"feathers-authentication-oauth2": "^0.2.5",
"feathers-configuration": "^0.4.1",
"feathers-errors": "^2.9.2",
"feathers-hooks": "^2.0.2",
"feathers-hooks-common": "^3.7.2",
"feathers-mongoose": "^5.1.2",
"feathers-rest": "^1.8.0",
"feathers-socketio": "^2.0.0"
}
const queue = require('./queue');
module.exports = (type, user, notifierOptions = {}) => {
if(!user) return Promise.resolve();
const test = notifierOptions.test || false;
if (type === 'resendVerifySignup') queue('sendVerificationEmail', { recipient: user, user, test });
if (type === 'sendResetPwd') queue('sendResetPasswordEmail', { recipient: user, user, test });
return Promise.resolve();
};
const { iff } = require('feathers-hooks-common');
const { authenticate } = require('feathers-authentication').hooks;
const authManagement = require('feathers-authentication-management');
// const authManagement = require('../packages/feathers-authentication-management/src');
const notifier = require('./auth.manager.notifier');
const onUserPasswordChange = require('./hooks/onUserPasswordChange');
const isAction = require('./hooks/isAction');
module.exports = function () {
const app = this;
app.configure(authManagement({
// users: app.service('users'),
notifier,
}));
app.service('authManagement').hooks({
before: {
create: [
iff(isAction('passwordChange', 'identityChange'), authenticate('jwt')),
iff(isAction('passwordChange'), onUserPasswordChange()),
],
},
});
};
require('dotenv').config();
const compress = require('compression');
const cors = require('cors');
const helmet = require('helmet');
const bodyParser = require('body-parser');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const handler = require('feathers-errors/handler');
const notFound = require('feathers-errors/not-found');
const middleware = require('./middleware');
const services = require('./services');
const appHooks = require('./app.hooks');
const authentication = require('./authentication');
const authManager = require('./auth.manager');
const mongoose = require('./mongoose');
const app = feathers();
// Load app configuration
app.configure(configuration());
// Enable CORS, security, compression, favicon and body parsing
app.options('*', cors());
app.use(cors({ origin: true }));
app.use(helmet());
app.use(compress());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Set up Plugins and providers
app.configure(hooks());
app.configure(mongoose);
app.configure(rest());
app.configure(socketio());
app.configure(middleware);
app.configure(authentication);
app.configure(services);
app.configure(authManager);
// Configure a middleware for 404s and the error handler
app.use(notFound());
app.use(handler());
app.hooks(appHooks);
module.exports = app;