Skip to content

Commit 06afd41

Browse files
committed
Misc fixes
1 parent cd5bbe0 commit 06afd41

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

prisma/schema.prisma

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ model User {
2424
noteItems NoteItem[]
2525
}
2626

27-
2827
enum VaultItemType {
2928
PASSWORD
3029
CARD
@@ -33,18 +32,18 @@ enum VaultItemType {
3332
}
3433

3534
model PasswordItem {
36-
id String @id @default(uuid())
37-
type VaultItemType @default(PASSWORD)
38-
website String
39-
username String
40-
password String
41-
usernameIV String
42-
websiteIV String
43-
passwordIV String
44-
createdAt DateTime @default(now())
45-
updatedAt DateTime @updatedAt
46-
userId String
47-
user User @relation(fields: [userId], references: [id])
35+
id String @id @default(uuid())
36+
type VaultItemType @default(PASSWORD)
37+
website String
38+
username String
39+
password String
40+
usernameIV String
41+
websiteIV String
42+
passwordIV String
43+
createdAt DateTime @default(now())
44+
updatedAt DateTime @updatedAt
45+
userId String
46+
user User @relation(fields: [userId], references: [id])
4847
}
4948

5049
model CardItem {

src/app/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function updatePasswordItem(
3737
throw new Error("Password item not found");
3838
}
3939

40-
await prismadb.passwordItem.update({
40+
const item = await prismadb.passwordItem.update({
4141
where: {
4242
id: passwordItem.id,
4343
},
@@ -51,7 +51,7 @@ export async function updatePasswordItem(
5151
},
5252
});
5353

54-
return { success: true };
54+
return item;
5555
}
5656

5757
export async function deletePasswordItem(id: string) {

src/components/vault/dialogs/edit-password-dialog.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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";
33
import {
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";
1617
import * as React from "react";
17-
import {useEffect,useState} from "react";
18+
import { useEffect, useState } from "react";
1819
import toast from "react-hot-toast";
19-
import {z} from "zod";
20+
import { z } from "zod";
2021

2122
interface 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}>

src/components/vault/vault-page.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ interface PasswordEntry {
3333
username: string;
3434
website: string;
3535
password: string;
36-
iv: string;
36+
usernameIV: string;
37+
websiteIV: string;
38+
passwordIV: string;
3739
updatedAt: string;
3840
lastAccess: string;
3941
created: string;
@@ -86,19 +88,31 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
8688

8789
useEffect(() => {
8890
if (!clerkUser) return;
89-
91+
9092
if (!user?.passwordItems || !passwordItems) return;
91-
93+
9294
const decryptPasswords = async () => {
9395
const decryptedPasswords = await Promise.all(
9496
passwordItems.map(async (item) => {
9597
try {
9698
const decryptedItem = {
9799
id: item.id,
98100
name: await decrypt(item.username, item.usernameIV, clerkUser.id),
99-
username: await decrypt(item.username, item.usernameIV, clerkUser.id),
100-
website: await decrypt(item.website, item.websiteIV, clerkUser.id),
101-
password: await decrypt(item.password, item.passwordIV, clerkUser.id),
101+
username: await decrypt(
102+
item.username,
103+
item.usernameIV,
104+
clerkUser.id
105+
),
106+
website: await decrypt(
107+
item.website,
108+
item.websiteIV,
109+
clerkUser.id
110+
),
111+
password: await decrypt(
112+
item.password,
113+
item.passwordIV,
114+
clerkUser.id
115+
),
102116
updatedAt: item.updatedAt.toISOString(),
103117
lastAccess: item.updatedAt.toISOString(),
104118
created: item.createdAt.toISOString(),
@@ -110,15 +124,16 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
110124
}
111125
})
112126
);
113-
127+
114128
setPasswords(
115-
decryptedPasswords.filter((item): item is PasswordEntry => item !== null)
129+
decryptedPasswords.filter(
130+
(item): item is PasswordEntry => item !== null
131+
)
116132
);
117133
};
118-
134+
119135
decryptPasswords();
120136
}, [user?.passwordItems, clerkUser, passwordItems]);
121-
122137

123138
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
124139
setSearchQuery(e.target.value);

0 commit comments

Comments
 (0)