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