@feathersjs/authentication-local
Advanced tools
Comparing version 5.0.0-pre.4 to 5.0.0-pre.5
@@ -6,2 +6,19 @@ # Change Log | ||
# [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23) | ||
### Bug Fixes | ||
* **hooks:** Migrate built-in hooks and allow backwards compatibility ([#2358](https://github.com/feathersjs/feathers/issues/2358)) ([759c5a1](https://github.com/feathersjs/feathers/commit/759c5a19327a731af965c3604119393b3d09a406)) | ||
* **koa:** Use extended query parser for compatibility ([#2397](https://github.com/feathersjs/feathers/issues/2397)) ([b2944ba](https://github.com/feathersjs/feathers/commit/b2944bac3ec6d5ecc80dc518cd4e58093692db74)) | ||
### Features | ||
* **adapter-commons:** Add support for params.adapter option and move memory adapter to @feathersjs/memory ([#2367](https://github.com/feathersjs/feathers/issues/2367)) ([a43e7da](https://github.com/feathersjs/feathers/commit/a43e7da22b6b981a96d1321736ea9a0cb924fb4f)) | ||
# [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13) | ||
@@ -8,0 +25,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { HookContext } from '@feathersjs/feathers'; | ||
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
export interface HashPasswordOptions { | ||
@@ -6,2 +6,2 @@ authentication?: string; | ||
} | ||
export default function hashPassword(field: string, options?: HashPasswordOptions): (context: HookContext<any, any>) => Promise<HookContext<any, any>>; | ||
export default function hashPassword(field: string, options?: HashPasswordOptions): (context: HookContext<any, any>, next?: NextFunction) => Promise<void>; |
@@ -25,32 +25,29 @@ "use strict"; | ||
} | ||
return (context) => __awaiter(this, void 0, void 0, function* () { | ||
if (context.type !== 'before') { | ||
throw new Error('The \'hashPassword\' hook should only be used as a \'before\' hook'); | ||
} | ||
return (context, next) => __awaiter(this, void 0, void 0, function* () { | ||
const { app, data, params } = context; | ||
if (data === undefined) { | ||
debug('hook.data is undefined. Skipping hashPassword hook.'); | ||
return context; | ||
if (data !== undefined) { | ||
const authService = app.defaultAuthentication(options.authentication); | ||
const { strategy = 'local' } = options; | ||
if (!authService || typeof authService.getStrategies !== 'function') { | ||
throw new errors_1.BadRequest('Could not find an authentication service to hash password'); | ||
} | ||
const [localStrategy] = authService.getStrategies(strategy); | ||
if (!localStrategy || typeof localStrategy.hashPassword !== 'function') { | ||
throw new errors_1.BadRequest(`Could not find '${strategy}' strategy to hash password`); | ||
} | ||
const addHashedPassword = (data) => __awaiter(this, void 0, void 0, function* () { | ||
const password = get_1.default(data, field); | ||
if (password === undefined) { | ||
debug(`hook.data.${field} is undefined, not hashing password`); | ||
return data; | ||
} | ||
const hashedPassword = yield localStrategy.hashPassword(password, params); | ||
return set_1.default(cloneDeep_1.default(data), field, hashedPassword); | ||
}); | ||
context.data = Array.isArray(data) ? yield Promise.all(data.map(addHashedPassword)) : | ||
yield addHashedPassword(data); | ||
} | ||
const authService = app.defaultAuthentication(options.authentication); | ||
const { strategy = 'local' } = options; | ||
if (!authService || typeof authService.getStrategies !== 'function') { | ||
throw new errors_1.BadRequest('Could not find an authentication service to hash password'); | ||
if (typeof next === 'function') { | ||
yield next(); | ||
} | ||
const [localStrategy] = authService.getStrategies(strategy); | ||
if (!localStrategy || typeof localStrategy.hashPassword !== 'function') { | ||
throw new errors_1.BadRequest(`Could not find '${strategy}' strategy to hash password`); | ||
} | ||
const addHashedPassword = (data) => __awaiter(this, void 0, void 0, function* () { | ||
const password = get_1.default(data, field); | ||
if (password === undefined) { | ||
debug(`hook.data.${field} is undefined, not hashing password`); | ||
return data; | ||
} | ||
const hashedPassword = yield localStrategy.hashPassword(password, params); | ||
return set_1.default(cloneDeep_1.default(data), field, hashedPassword); | ||
}); | ||
context.data = Array.isArray(data) ? yield Promise.all(data.map(addHashedPassword)) : | ||
yield addHashedPassword(data); | ||
return context; | ||
}); | ||
@@ -57,0 +54,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { HookContext } from '@feathersjs/feathers'; | ||
declare const _default: (...fields: string[]) => (context: HookContext<any, any>) => HookContext<any, any>; | ||
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
declare const _default: (...fields: string[]) => (context: HookContext<any, any>, next?: NextFunction) => Promise<void>; | ||
export default _default; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,4 +16,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const omit_1 = __importDefault(require("lodash/omit")); | ||
exports.default = (...fields) => (context) => { | ||
const result = context.dispatch || context.result; | ||
exports.default = (...fields) => (context, next) => __awaiter(void 0, void 0, void 0, function* () { | ||
const o = (current) => { | ||
@@ -18,21 +26,23 @@ if (typeof current === 'object' && !Array.isArray(current)) { | ||
}; | ||
if (!result) { | ||
return context; | ||
if (typeof next === 'function') { | ||
yield next(); | ||
} | ||
if (Array.isArray(result)) { | ||
context.dispatch = result.map(o); | ||
const result = context.dispatch || context.result; | ||
if (result) { | ||
if (Array.isArray(result)) { | ||
context.dispatch = result.map(o); | ||
} | ||
else if (result.data && context.method === 'find') { | ||
context.dispatch = Object.assign({}, result, { | ||
data: result.data.map(o) | ||
}); | ||
} | ||
else { | ||
context.dispatch = o(result); | ||
} | ||
if (context.params && context.params.provider) { | ||
context.result = context.dispatch; | ||
} | ||
} | ||
else if (result.data && context.method === 'find') { | ||
context.dispatch = Object.assign({}, result, { | ||
data: result.data.map(o) | ||
}); | ||
} | ||
else { | ||
context.dispatch = o(result); | ||
} | ||
if (context.params && context.params.provider) { | ||
context.result = context.dispatch; | ||
} | ||
return context; | ||
}; | ||
}); | ||
//# sourceMappingURL=protect.js.map |
import hashPassword from './hooks/hash-password'; | ||
export declare const hooks: { | ||
hashPassword: typeof hashPassword; | ||
protect: (...fields: string[]) => (context: import("@feathersjs/feathers/lib").HookContext<any, any>) => import("@feathersjs/feathers/lib").HookContext<any, any>; | ||
protect: (...fields: string[]) => (context: import("@feathersjs/feathers/lib").HookContext<any, any>, next?: import("@feathersjs/hooks/lib").NextFunction) => Promise<void>; | ||
}; | ||
export { LocalStrategy } from './strategy'; |
{ | ||
"name": "@feathersjs/authentication-local", | ||
"description": "Local authentication strategy for @feathers/authentication", | ||
"version": "5.0.0-pre.4", | ||
"version": "5.0.0-pre.5", | ||
"homepage": "https://feathersjs.com", | ||
@@ -55,6 +55,6 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/authentication": "^5.0.0-pre.4", | ||
"@feathersjs/commons": "^5.0.0-pre.4", | ||
"@feathersjs/errors": "^5.0.0-pre.4", | ||
"@feathersjs/feathers": "^5.0.0-pre.4", | ||
"@feathersjs/authentication": "^5.0.0-pre.5", | ||
"@feathersjs/commons": "^5.0.0-pre.5", | ||
"@feathersjs/errors": "^5.0.0-pre.5", | ||
"@feathersjs/feathers": "^5.0.0-pre.5", | ||
"bcryptjs": "^2.4.3", | ||
@@ -64,14 +64,13 @@ "lodash": "^4.17.21" | ||
"devDependencies": { | ||
"@feathersjs/adapter-memory": "^5.0.0-pre.4", | ||
"@feathersjs/memory": "^5.0.0-pre.5", | ||
"@types/bcryptjs": "^2.4.2", | ||
"@types/debug": "^4.1.5", | ||
"@types/lodash": "^4.14.169", | ||
"@types/lodash": "^4.14.170", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^15.0.3", | ||
"@types/node": "^15.12.1", | ||
"mocha": "^8.4.0", | ||
"shx": "^0.3.3", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4" | ||
"ts-node": "^10.0.0", | ||
"typescript": "^4.3.2" | ||
}, | ||
"gitHead": "d2f1d200b6d9a790a03dc3e6e345f4e0ab726720" | ||
"gitHead": "738f84f91fb72d5e10a0bf57b58db75b0b03d3ff" | ||
} |
@@ -6,3 +6,3 @@ import get from 'lodash/get'; | ||
import { createDebug } from '@feathersjs/commons'; | ||
import { HookContext } from '@feathersjs/feathers'; | ||
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
import { LocalStrategy } from '../strategy'; | ||
@@ -22,45 +22,40 @@ | ||
return async (context: HookContext<any, any>) => { | ||
if (context.type !== 'before') { | ||
throw new Error('The \'hashPassword\' hook should only be used as a \'before\' hook'); | ||
} | ||
return async (context: HookContext<any, any>, next?: NextFunction) => { | ||
const { app, data, params } = context; | ||
if (data === undefined) { | ||
debug('hook.data is undefined. Skipping hashPassword hook.'); | ||
return context; | ||
} | ||
if (data !== undefined) { | ||
const authService = app.defaultAuthentication(options.authentication); | ||
const { strategy = 'local' } = options; | ||
const authService = app.defaultAuthentication(options.authentication); | ||
const { strategy = 'local' } = options; | ||
if (!authService || typeof authService.getStrategies !== 'function') { | ||
throw new BadRequest('Could not find an authentication service to hash password'); | ||
} | ||
if (!authService || typeof authService.getStrategies !== 'function') { | ||
throw new BadRequest('Could not find an authentication service to hash password'); | ||
} | ||
const [ localStrategy ] = authService.getStrategies(strategy) as LocalStrategy[]; | ||
const [ localStrategy ] = authService.getStrategies(strategy) as LocalStrategy[]; | ||
if (!localStrategy || typeof localStrategy.hashPassword !== 'function') { | ||
throw new BadRequest(`Could not find '${strategy}' strategy to hash password`); | ||
} | ||
if (!localStrategy || typeof localStrategy.hashPassword !== 'function') { | ||
throw new BadRequest(`Could not find '${strategy}' strategy to hash password`); | ||
} | ||
const addHashedPassword = async (data: any) => { | ||
const password = get(data, field); | ||
const addHashedPassword = async (data: any) => { | ||
const password = get(data, field); | ||
if (password === undefined) { | ||
debug(`hook.data.${field} is undefined, not hashing password`); | ||
return data; | ||
} | ||
if (password === undefined) { | ||
debug(`hook.data.${field} is undefined, not hashing password`); | ||
return data; | ||
const hashedPassword: string = await localStrategy.hashPassword(password, params); | ||
return set(cloneDeep(data), field, hashedPassword); | ||
} | ||
const hashedPassword: string = await localStrategy.hashPassword(password, params); | ||
context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) : | ||
await addHashedPassword(data); | ||
} | ||
return set(cloneDeep(data), field, hashedPassword); | ||
if (typeof next === 'function') { | ||
await next(); | ||
} | ||
context.data = Array.isArray(data) ? await Promise.all(data.map(addHashedPassword)) : | ||
await addHashedPassword(data); | ||
return context; | ||
}; | ||
} |
import omit from 'lodash/omit'; | ||
import { HookContext } from '@feathersjs/feathers'; | ||
import { HookContext, NextFunction } from '@feathersjs/feathers'; | ||
export default (...fields: string[]) => (context: HookContext<any, any>) => { | ||
const result = context.dispatch || context.result; | ||
export default (...fields: string[]) => async (context: HookContext<any, any>, next?: NextFunction) => { | ||
const o = (current: any) => { | ||
@@ -17,21 +16,23 @@ if (typeof current === 'object' && !Array.isArray(current)) { | ||
if (!result) { | ||
return context; | ||
if (typeof next === 'function') { | ||
await next(); | ||
} | ||
if (Array.isArray(result)) { | ||
context.dispatch = result.map(o); | ||
} else if (result.data && context.method === 'find') { | ||
context.dispatch = Object.assign({}, result, { | ||
data: result.data.map(o) | ||
}); | ||
} else { | ||
context.dispatch = o(result); | ||
} | ||
const result = context.dispatch || context.result; | ||
if (context.params && context.params.provider) { | ||
context.result = context.dispatch; | ||
if (result) { | ||
if (Array.isArray(result)) { | ||
context.dispatch = result.map(o); | ||
} else if (result.data && context.method === 'find') { | ||
context.dispatch = Object.assign({}, result, { | ||
data: result.data.map(o) | ||
}); | ||
} else { | ||
context.dispatch = o(result); | ||
} | ||
if (context.params && context.params.provider) { | ||
context.result = context.dispatch; | ||
} | ||
} | ||
return context; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60130
9
441