Skip to content

Commit 72730c2

Browse files
committed
Rewrite
1 parent fc0f551 commit 72730c2

22 files changed

Lines changed: 970 additions & 1495 deletions

package-lock.json

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@
6060
"react-day-picker": "^9.3.2",
6161
"react-dom": "^18",
6262
"react-hook-form": "^7.53.2",
63-
"react-hot-toast": "^2.4.1",
63+
"react-hot-toast": "^2.5.1",
6464
"react-query": "^3.39.3",
6565
"react-resizable-panels": "^2.1.7",
6666
"sonner": "^1.7.0",
6767
"tailwind-merge": "^2.5.4",
6868
"tailwindcss-animate": "^1.0.7",
6969
"vaul": "^1.1.1",
70-
"zod": "^3.23.8",
70+
"zod": "^3.24.1",
7171
"zustand": "^5.0.1"
7272
},
7373
"devDependencies": {

src/app/(main)/layout.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/app/(main)/page.tsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
import {Icons} from "@/components/ui/icons";
2-
import VaultPage from "@/components/ui/vault/vault";
1+
import { Icons } from "@/components/ui/icons";
2+
import { VaultPage } from "@/components/ui/password-manager";
33
import prismadb from "@/lib/prismadb";
4-
import {RedirectToSignIn,SignedOut} from "@clerk/nextjs";
5-
import {auth} from "@clerk/nextjs/server";
4+
import { RedirectToSignIn, SignedOut } from "@clerk/nextjs";
5+
import { auth } from "@clerk/nextjs/server";
66

7-
export const dynamic = 'force-dynamic';
7+
export const dynamic = "force-dynamic";
88

99
const Page = async () => {
10-
const { userId } = await auth();
10+
const { userId, redirectToSignIn } = await auth();
1111

12-
if (!userId) {
13-
return (
14-
<div className="h-screen w-[calc(100vw-var(--sidebar-width))] flex justify-center items-center animate-pulse">
15-
<Icons.logo className="w-40 h-40" />
16-
<h1 className="font-bold tracking-tig text-7xl">Authenticating</h1>
17-
18-
<SignedOut>
19-
<RedirectToSignIn />
20-
</SignedOut>
21-
</div>
22-
);
23-
}
12+
if (!userId) return redirectToSignIn();
2413

2514
const user = await prismadb.user.findUnique({
2615
where: {

src/app/actions.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
"use server";
2+
3+
import prismadb from "@/lib/prismadb";
4+
import { auth, currentUser } from "@clerk/nextjs/server";
5+
6+
export async function updatePasswordItem(
7+
id: string,
8+
newUsername: string,
9+
newWebsite: string,
10+
newPassword: string
11+
) {
12+
const clerkUser = await currentUser();
13+
14+
const user = await prismadb.user.findUnique({
15+
where: {
16+
id: clerkUser?.id,
17+
},
18+
include: {
19+
passwordItems: true,
20+
},
21+
});
22+
23+
if (!user) {
24+
throw new Error("User not found");
25+
}
26+
27+
const passwordItem = user.passwordItems.find((item) => item.id === id);
28+
29+
if (!passwordItem) {
30+
throw new Error("Password item not found");
31+
}
32+
33+
await prismadb.passwordItem.update({
34+
where: {
35+
id: passwordItem.id,
36+
},
37+
data: {
38+
username: newUsername,
39+
website: newWebsite,
40+
password: newPassword,
41+
},
42+
});
43+
44+
return { success: true };
45+
}
46+
47+
export async function deletePasswordItem(id: string) {
48+
const clerkUser = await currentUser();
49+
50+
const user = await prismadb.user.findUnique({
51+
where: {
52+
id: clerkUser?.id,
53+
},
54+
include: {
55+
passwordItems: true,
56+
},
57+
});
58+
59+
if (!user) {
60+
throw new Error("User not found");
61+
}
62+
63+
const passwordItem = user.passwordItems.find((item) => item.id === id);
64+
65+
if (!passwordItem) {
66+
throw new Error("Password item not found");
67+
}
68+
69+
await prismadb.passwordItem.delete({
70+
where: {
71+
id: passwordItem.id,
72+
},
73+
});
74+
75+
return { success: true };
76+
}
77+
78+
export async function createPasswordItem(
79+
username: string,
80+
website: string,
81+
password: string
82+
) {
83+
const clerkUser = await currentUser();
84+
85+
if (!clerkUser) {
86+
throw new Error("User not authenticated");
87+
}
88+
89+
const user = await prismadb.user.findUnique({
90+
where: {
91+
id: clerkUser.id,
92+
},
93+
include: {
94+
passwordItems: true,
95+
},
96+
});
97+
98+
if (!user) {
99+
throw new Error("User not found");
100+
}
101+
102+
const newPasswordItem = await prismadb.passwordItem.create({
103+
data: {
104+
username,
105+
website,
106+
password,
107+
updatedAt: new Date().toISOString(),
108+
createdAt: new Date().toISOString(),
109+
userId: user.id,
110+
},
111+
});
112+
113+
return newPasswordItem;
114+
}
115+
116+
export async function instantiateVault() {
117+
const clerkUser = await currentUser();
118+
119+
const vault = await prismadb.user.create({
120+
data: {
121+
id: clerkUser?.id,
122+
username: clerkUser?.username!,
123+
},
124+
include: {
125+
passwordItems: true,
126+
cardItems: true,
127+
pinItems: true,
128+
noteItems: true,
129+
},
130+
});
131+
132+
return vault;
133+
}

src/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Metadata } from "next";
22
import "./globals.css";
33
import { ClerkProvider } from "@clerk/nextjs";
4-
4+
import { Toaster } from "react-hot-toast";
55

66
export const metadata: Metadata = {
77
title: "LockScript - Vault",
@@ -17,6 +17,7 @@ export default function RootLayout({
1717
<html lang="en">
1818
<ClerkProvider>
1919
<body>
20+
<Toaster />
2021
<main>{children}</main>
2122
</body>
2223
</ClerkProvider>

src/components/modals/alert-modal.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)