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

export default {
  Mutation: {
    createAccount: async (_, args) => {
      const { username, password, email } = args;

      const encryptPw = await bcrypt.hash(password, 10);
      const user = await prisma.user.create({
        data: {
          username,
          email,
          password: encryptPw,
        },
      });
      const token = generateToken(user.id);
      return { token, user };
    },
  },
};