1- import { updatePasswordItem } from "@/app/actions" ;
2- import { Button } from "@/components/ui/button" ;
1+ import { updatePasswordItem } from "@/app/actions" ;
2+ import { Button } from "@/components/ui/button" ;
33import {
44 Dialog ,
55 DialogContent ,
@@ -8,15 +8,16 @@ import {
88 DialogHeader ,
99 DialogTitle ,
1010} from "@/components/ui/dialog" ;
11- import { Input } from "@/components/ui/input" ;
12- import { encrypt } from "@/utils/encryption" ;
13- import { useUser } from "@clerk/nextjs" ;
14- import { Globe , Loader2 } from "lucide-react" ;
15- import { useRouter } from "next/navigation" ;
11+ import { Input } from "@/components/ui/input" ;
12+ import prismadb from "@/lib/prismadb" ;
13+ import { encrypt } from "@/utils/encryption" ;
14+ import { useUser } from "@clerk/nextjs" ;
15+ import { Globe , Loader2 } from "lucide-react" ;
16+ import { useRouter } from "next/navigation" ;
1617import * as React from "react" ;
17- import { useEffect , useState } from "react" ;
18+ import { useEffect , useState } from "react" ;
1819import toast from "react-hot-toast" ;
19- import { z } from "zod" ;
20+ import { z } from "zod" ;
2021
2122interface PasswordEntry {
2223 id : string ;
@@ -80,53 +81,59 @@ export function EditPasswordDialog({
8081
8182 const handleSave = async ( ) => {
8283 setLoading ( true ) ;
83-
84+
8485 const validationResult = passwordSchema . safeParse ( {
8586 name : editedEntry . name ,
8687 username : editedEntry . username ,
8788 website : editedEntry . website ,
8889 password : editedEntry . password ,
8990 } ) ;
90-
91+
9192 if ( ! validationResult . success ) {
9293 const errorMessage =
9394 validationResult . error . errors [ 0 ] ?. message || "Validation failed" ;
9495 toast . error ( errorMessage ) ;
9596 setLoading ( false ) ;
9697 return ;
9798 }
98-
99+
99100 if ( ! user ) {
100101 toast . error ( "User not found" ) ;
101102 setLoading ( false ) ;
102103 return ;
103104 }
104-
105+
106+ if ( ! entry ) {
107+ toast . error ( "Entry not found" ) ;
108+ setLoading ( false ) ;
109+ return ;
110+ }
111+
105112 try {
106113 const encryptedUsername = await encrypt ( editedEntry . username , user . id ) ;
107114 const encryptedWebsite = await encrypt ( editedEntry . website , user . id ) ;
108115 const encryptedPassword = await encrypt ( editedEntry . password , user . id ) ;
109-
110- updatePasswordItem (
111- entry ! . id ,
116+
117+ await updatePasswordItem (
118+ entry . id ,
112119 encryptedUsername . encryptedData ,
113120 encryptedWebsite . encryptedData ,
114121 encryptedPassword . encryptedData ,
115- encryptedUsername . iv ,
122+ encryptedUsername . iv ,
116123 encryptedWebsite . iv ,
117- encryptedPassword . iv ,
124+ encryptedPassword . iv
118125 ) ;
119-
126+
120127 router . refresh ( ) ;
121128 toast . success ( "Password updated" ) ;
129+
122130 onClose ( ) ;
123131 } catch ( error ) {
124132 toast . error ( "Failed to update password" ) ;
125133 } finally {
126134 setLoading ( false ) ;
127135 }
128136 } ;
129-
130137
131138 return (
132139 < Dialog open = { isOpen } onOpenChange = { onClose } >
0 commit comments