UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.passwordHash = exports.LocalStrategy = exports.hooks = void 0;
7const hash_password_1 = __importDefault(require("./hooks/hash-password"));
8const protect_1 = __importDefault(require("./hooks/protect"));
9const strategy_1 = require("./strategy");
10Object.defineProperty(exports, "LocalStrategy", { enumerable: true, get: function () { return strategy_1.LocalStrategy; } });
11exports.hooks = { hashPassword: hash_password_1.default, protect: protect_1.default };
12/**
13 * Returns as property resolver that hashes a given plain text password using a Local
14 * authentication strategy.
15 *
16 * @param options The authentication `service` and `strategy` name
17 * @returns
18 */
19const passwordHash = (options) => async (value, _data, context) => {
20 if (value === undefined) {
21 return value;
22 }
23 const { app, params } = context;
24 const authService = app.defaultAuthentication(options.service);
25 const localStrategy = authService.getStrategy(options.strategy);
26 return localStrategy.hashPassword(value, params);
27};
28exports.passwordHash = passwordHash;
29//# sourceMappingURL=index.js.map
\No newline at end of file