我正在实施 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)