createAccount.js 560 Bytes
import { prisma, generateToken } from "../../../utils";
import bcrypt from "bcryptjs";

export default {
  Mutation: {
    createAccount: async (_, args) => {
      const { name, password, email, bio = "", avatarUrl = "" } = args;
      const encryptPw = await bcrypt.hash(password, 10);
      const user = await prisma.user.create({
        data: {
          name,
          email,
          bio,
          avatarUrl,
          password: encryptPw,
        },
      });
      const token = generateToken(user.id);
      return { token, user };
    },
  },
};