freeCodeCamp/server/services/user.js

35 lines
752 B
JavaScript
Raw Normal View History

import debugFactory from 'debug';
const censor = '**********************:P********';
2016-01-27 19:34:44 +00:00
const debug = debugFactory('fcc:services:user');
const protectedUserFields = {
password: censor,
profiles: censor
};
2015-10-30 00:09:26 +00:00
export default function userServices() {
return {
name: 'user',
read: (req, resource, params, config, cb) => {
let { user } = req;
if (user) {
debug('user is signed in');
// Zalgo!!!
return process.nextTick(() => {
2016-03-21 22:39:45 +00:00
cb(
null,
{
...user.toJSON(),
...protectedUserFields
}
);
});
}
debug('user is not signed in');
return process.nextTick(() => {
cb(null, {});
});
}
};
}