sdy

update confirmEmailSecret

type Mutation {
confirmEmailSecret(secret: String!, email: String!): String!
}
import { prisma, generateToken } from "../../../utils";
export default {
Mutation: {
confirmEmailSecret: async (_, args) => {
const { secret, email } = args;
const user = await prisma.user.findOne({
where: {
email,
},
});
if (user.emailSecret !== secret) {
throw new Error(
"not vaild secret value!, input another value or resend email"
);
} else {
// TODO: Update emailSecret in prisma
await prisma.user.update({
where: {
email,
},
data: {
emailSecret: "",
},
});
return generateToken(user.id);
}
},
},
};