UNPKG

feathers-authentication-management

Version:

Adds sign up verification, forgotten password reset, and other capabilities to local feathers-authentication

44 lines (43 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeVerification = void 0; const feathers_hooks_common_1 = require("feathers-hooks-common"); /** * Sanitize users. After-hook for '/users' service. */ function removeVerification(ifReturnTokens) { return (context) => { (0, feathers_hooks_common_1.checkContext)(context, 'after'); // Retrieve the items from the hook const items = (0, feathers_hooks_common_1.getItems)(context); if (!items) return; const isArray = Array.isArray(items); const users = (isArray ? items : [items]); users.forEach((user) => { if (!('isVerified' in user) && context.method === 'create') { /* eslint-disable no-console */ console.warn('Property isVerified not found in user properties. (removeVerification)'); console.warn("Have you added authManagement's properties to your model? (Refer to README)"); console.warn('Have you added the addVerification hook on users::create?'); /* eslint-enable */ } if (context.params.provider && user) { // noop if initiated by server delete user.verifyExpires; delete user.resetExpires; delete user.verifyChanges; if (!ifReturnTokens) { delete user.verifyToken; delete user.verifyShortToken; delete user.resetToken; delete user.resetShortToken; } } }); // Replace the items within the hook (0, feathers_hooks_common_1.replaceItems)(context, isArray ? users : users[0]); return context; }; } exports.removeVerification = removeVerification;