1
0
mirror of synced 2025-12-19 18:11:23 -05:00

Add try/catch in change password mutation (#3337)

* Revert "Update change password w/ try/catch"

This reverts commit 186532ef2d.

* Update changePassword.ts

* Update packages/generator/templates/app/app/auth/mutations/changePassword.ts

Co-authored-by: Aleksandra <alexsandra.sikora@gmail.com>

* Update changePassword.ts

* Apply suggestions from code review

Co-authored-by: Aleksandra <alexsandra.sikora@gmail.com>
This commit is contained in:
Blake Bayer
2022-05-10 05:27:13 -04:00
committed by GitHub
parent b84ed74496
commit 919465c9b6

View File

@@ -1,4 +1,4 @@
import { NotFoundError, SecurePassword, resolver } from "blitz"
import { NotFoundError, SecurePassword, resolver, AuthenticationError } from "blitz"
import db from "db"
import { authenticateUser } from "./login"
import { ChangePassword } from "../validations"
@@ -10,7 +10,15 @@ export default resolver.pipe(
const user = await db.user.findFirst({ where: { id: ctx.session.userId! } })
if (!user) throw new NotFoundError()
await authenticateUser(user.email, currentPassword)
try {
await authenticateUser(user.email, currentPassword)
} catch (error: any) {
if (error instanceof AuthenticationError) {
throw new Error("Invalid Password")
}
throw error
}
const hashedPassword = await SecurePassword.hash(newPassword.trim())
await db.user.update({