Ocelot-Social/backend/src/middleware/passwordMiddleware.js
Wolfgang Huß 95a0567e69 Query of users "publicKey" 'throws "Not Authorised!"'
Changes password and permission middleware.

Thanks for your big help @roschaefer !
2019-04-11 20:01:20 +02:00

22 lines
644 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) => {
let result = await resolve(root, args, context, info)
result = walkRecursive(result, ['password', 'privatKey'], () => {
// replace password with asterisk
return '*****'
})
return result
}
}