feathers-authentication
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -22,4 +22,19 @@ 'use strict'; | ||
return function (hook) { | ||
function setId(obj) { | ||
obj[destProp] = hook.params.user[sourceProp]; | ||
} | ||
if (hook.params.user) { | ||
hook.data[destProp] = hook.params.user[sourceProp]; | ||
// Handle arrays. | ||
if (Array.isArray(hook.data)) { | ||
hook.data.forEach(function (item) { | ||
setId(item); | ||
}); | ||
// Handle single objects. | ||
} else { | ||
setId(hook.data); | ||
} | ||
} else { | ||
@@ -26,0 +41,0 @@ throw new Error('There is no user logged in.'); |
@@ -17,9 +17,23 @@ 'use strict'; | ||
} | ||
function convert(obj) { | ||
if (obj[fieldName] && obj[fieldName].toLowercase) { | ||
obj[fieldName] = obj[fieldName].toLowerCase(); | ||
} | ||
} | ||
return function (hook) { | ||
var location = hook.type === 'before' ? 'data' : 'params'; | ||
// Allow user to view records without a userId. | ||
if (hook[location][fieldName] && hook[location][fieldName].toLowercase) { | ||
hook[location][fieldName] = hook[location][fieldName].toLowerCase(); | ||
} | ||
var location = hook.type === 'before' ? 'data' : 'result'; | ||
// Handle arrays. | ||
if (Array.isArray(hook[location])) { | ||
hook[location].forEach(function (item) { | ||
convert(item); | ||
}); | ||
// Handle Single Objects. | ||
} else { | ||
convert(hook[location]); | ||
} | ||
}; | ||
} |
{ | ||
"name": "feathers-authentication", | ||
"description": "Add Authentication to your FeathersJS app.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/feathersjs/feathers-authentication", | ||
@@ -6,0 +6,0 @@ "main": "lib/", |
31713
654