implement update user, update password and delete account

This commit is contained in:
m5r
2021-09-25 07:09:20 +08:00
parent 12983316f5
commit c9b657e44c
11 changed files with 220 additions and 83 deletions

View File

@ -1,24 +0,0 @@
import { NotFoundError, SecurePassword, resolver } from "blitz";
import db from "../../../db";
import { authenticateUser } from "./login";
import { ChangePassword } from "../validations";
export default resolver.pipe(
resolver.zod(ChangePassword),
resolver.authorize(),
async ({ currentPassword, newPassword }, ctx) => {
const user = await db.user.findFirst({ where: { id: ctx.session.userId! } });
if (!user) throw new NotFoundError();
await authenticateUser(user.email, currentPassword);
const hashedPassword = await SecurePassword.hash(newPassword.trim());
await db.user.update({
where: { id: user.id },
data: { hashedPassword },
});
return true;
},
);

View File

@ -1,4 +1,4 @@
import { Ctx } from "blitz";
import type { Ctx } from "blitz";
export default async function logout(_ = null, ctx: Ctx) {
return await ctx.session.$revoke();