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

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