sdy

update createAccout resolver

1 -import { prisma } from "../../../middlewares"; 1 +import { prisma } from "../../../utils";
2 +import bcrypt from "bcryptjs";
3 +import jwt from "jsonwebtoken";
2 4
3 export default { 5 export default {
4 Mutation: { 6 Mutation: {
5 createAccount: async (_, args) => { 7 createAccount: async (_, args) => {
6 - const { name, email, bio = "", avatarUrl = "" } = args; 8 + const { name, password, email, bio = "", avatarUrl = "" } = args;
9 + const encryptPw = await bcrypt.hash(password, 10);
7 const user = await prisma.user.create({ 10 const user = await prisma.user.create({
8 data: { 11 data: {
9 name, 12 name,
10 email, 13 email,
11 bio, 14 bio,
12 avatarUrl, 15 avatarUrl,
16 + password: encryptPw,
13 }, 17 },
14 }); 18 });
15 - return user; 19 + const token = jwt.sign({
20 + id: user.id,
21 + });
22 + return { token, user };
16 }, 23 },
17 }, 24 },
18 }; 25 };
......