Ocelot-Social/backend/src/middleware/passwordMiddleware.js
2019-03-20 21:00:59 +01:00

21 lines
613 B
JavaScript

import bcrypt from 'bcryptjs'
import walkRecursive from '../helpers/walkRecursive'
export default {
Mutation: {
CreateUser: async (resolve, root, args, context, info) => {
args.password = await bcrypt.hashSync(args.password, 10)
const result = await resolve(root, args, context, info)
result.password = '*****'
return result
}
},
Query: async (resolve, root, args, context, info) => {
const result = await resolve(root, args, context, info)
return walkRecursive(result, ['password'], () => {
// replace password with asterisk
return '*****'
})
}
}