UNPKG

@batolye/bdk-core

Version:

Module to provide core utilities for BulusAtolyesi applications and services

91 lines (87 loc) 2.73 kB
"use strict"; var _hooks = require("../../hooks"); const { hashPassword } = require("@feathersjs/authentication-local").hooks; const commonHooks = require("feathers-hooks-common"); module.exports = { before: { all: [], find: [], get: [], create: [commonHooks.when(hook => hook.data.googleId, (0, _hooks.serialize)([{ source: "google.profile.displayName", target: "name" }, { source: "google.profile.emails[0].value", target: "email" }], { throwOnNotFound: true })), commonHooks.when(hook => hook.data.githubId, (0, _hooks.serialize)([{ source: "github.profile.displayName", target: "name" }, { source: "github.profile.emails[0].value", target: "email" }], { throwOnNotFound: true })), (0, _hooks.serialize)([{ source: "name", target: "profile.name", delete: true }, { source: "email", target: "profile.description" }], { throwOnNotFound: true }), (0, _hooks.serialize)([// Enforcing password policy requires both the clear and hashed password, // Keep track of clear password here since hashPassword() remove it // FIXME: for testing purpose we create users without a password for now // should it be fixed for safety ? { source: "password", target: "clearPassword" }], { throwOnNotFound: false }), hashPassword(), (0, _hooks.enforcePasswordPolicy)({ userAsItem: true }), // Now we have enforced password policy remove the clear password // (we only store hashed password for safety) commonHooks.discard("clearPassword")], // when changing password store previous one for password policy update: [commonHooks.when(hook => hook.data.password && hook.app.core_getPasswordPolicy, _hooks.populatePreviousObject, (0, _hooks.storePreviousPassword)({ userAsItem: true }))], patch: [commonHooks.when(hook => hook.data.password && hook.app.core_getPasswordPolicy, _hooks.populatePreviousObject, (0, _hooks.storePreviousPassword)({ userAsItem: true }))], remove: [] }, after: { all: [commonHooks.when(hook => hook.params.provider, commonHooks.discard("password"), commonHooks.discard("previousPasswords")), (0, _hooks.serialize)([{ source: "profile.name", target: "name" }, { source: "profile.avatar", target: "avatar" }, { source: "profile.description", target: "description" }])], find: [], get: [], create: [(0, _hooks.core_updateAbilities)()], update: [], patch: [], remove: [] }, error: { all: [], find: [], get: [], create: [], update: [], patch: [], remove: [] } };