小编jch*_*che的帖子

GraphQL 突变“在发送到客户端后无法设置标头”

我正在实施 graphql 登录突变来验证用户登录凭据。Mutation 使用 bcrypt 验证密码,然后将 cookie 发送到客户端,客户端将根据 cookie 是买家还是所有者用户来呈现用户配置文件。

GraphQL 登录突变代码:

const Mutation = new GraphQLObjectType({
    name: 'Mutation',
    fields: {
    loginUser: {
            type: UserType,
            args: {
                email: { type: GraphQLString },
                password: { type: GraphQLString }
            },
            resolve: function (parent, args, { req, res }) {
                User.findOne({ email: args.email }, (err, user) => {
                    if (user) {
                        bcrypt.compare(args.password, user.password).then(isMatch => {
                            if (isMatch) {
                                if (!user.owner) {
                                    res.cookie('cookie', "buyer", { maxAge: 900000, httpOnly: false, path: '/' });
                                } else …
Run Code Online (Sandbox Code Playgroud)

response-headers graphql express-graphql graphql-mutation

1
推荐指数
1
解决办法
2421
查看次数