小编Jer*_*rry的帖子

如何修复 TypeError:在使用 bcryptjs 进行 GraphQL 突变的哈希密码期间无法读取未定义的属性“哈希”?

我对 Node/GraphQL/MongoDB/Moogose 比较陌生。我正在尝试创建一个突变来使用 bcryptjs 而不是纯文本来加密用户的密码。但是,我遇到了此错误: TypeError:无法读取未定义的属性“哈希”

我来自 Python 背景,我在理解异步编程时遇到一些困难这是我的 schema.js 的代码块

const RootMutation = new GraphQLObjectType({
    name: 'RootMutationType',
    fields: {
    createUser: {
        type: UserType,
        args: {
            email: { type: new GraphQLNonNull(GraphQLString) },
            password: { type: new GraphQLNonNull(GraphQLString) },
        },
        resolve(parents, args) {
            User.findOne({ email: args.email })
                .then(user => {
                    if(user) {
                        throw new Error('This email has already been used!');
                    }
                    return bcrypt.hash(args.password, 12);    // Error at this line
                })
                .then(hashedPassword => {
                    let user = new User({
                        email: args.email,
                        password: …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js graphql

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

graphql ×1

mongodb ×1

mongoose ×1

node.js ×1