diff --git a/README.md b/README.md index 0ee9392..236300d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,15 @@ + +## 📈 GitHub Repository Stats +| 🌟 **Stars** | 🍴 **Forks** | 🐛 **Issues** | 🔔 **Open PRs** | 🔕 **Closed PRs** | 🛠️ **Languages** | ✅ **Contributors** | +|--------------|--------------|---------------|-----------------|------------------|------------------|------------------| +| ![GitHub stars](https://img.shields.io/github/stars/MitulSonagara/truth-tunnel) | ![forks](https://img.shields.io/github/forks/MitulSonagara/truth-tunnel) | ![issues](https://img.shields.io/github/issues/MitulSonagara/truth-tunnel?color=32CD32) | ![pull requests](https://img.shields.io/github/issues-pr/MitulSonagara/truth-tunnel?color=FFFF8F) | ![Closed PRs](https://img.shields.io/github/issues-pr-closed/MitulSonagara/truth-tunnel?color=20B2AA) | ![Languages](https://img.shields.io/github/languages/count/MitulSonagara/truth-tunnel?color=20B2AA) | ![Contributors](https://img.shields.io/github/contributors/MitulSonagara/truth-tunnel?color=00FA9A) | + + + + ### This project is now OFFICIALLY accepted for diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 243a8c2..d571efc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -32,7 +32,7 @@ model EncryptionKey { publicKey String @unique userId String @unique @db.ObjectId testEncryption String @default("unsecured") - user User @relation(fields: [userId], references: [id]) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) } model Message { @@ -41,7 +41,7 @@ model Message { userId String @db.ObjectId createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - User User @relation(fields: [userId], references: [id]) + User User @relation(fields: [userId], references: [id], onDelete: Cascade) } model Account { diff --git a/src/app/(app)/dashboard/page.tsx b/src/app/(app)/dashboard/page.tsx index 4dc94b8..a9a6ee3 100644 --- a/src/app/(app)/dashboard/page.tsx +++ b/src/app/(app)/dashboard/page.tsx @@ -3,14 +3,22 @@ import { acceptMessageSchema } from "@/schemas/acceptMessageSchema"; import { zodResolver } from "@hookform/resolvers/zod"; import { toast } from "sonner"; import { useSession } from "next-auth/react"; -import React from "react"; +import React, { useEffect } from "react"; import { useForm } from "react-hook-form"; import { User } from "next-auth"; import { Button } from "@/components/ui/button"; import { Switch } from "@/components/ui/switch"; import Navbar from "@/components/Navbar"; import { Separator } from "@/components/ui/separator"; -import { Copy, ListX, Loader2, RefreshCcw, Search } from "lucide-react"; +import { + Edit3, + GlobeLockIcon, + ListX, + Loader2, + RefreshCcw, + Search, + Copy, +} from "lucide-react"; import { Input } from "@/components/ui/input"; import { useDeleteModal } from "@/stores/modals-store"; import GenerateEncryptionAlert from "@/components/alerts/generate-encryption-alert"; @@ -25,13 +33,43 @@ import Messages from "@/components/Messages"; import { useCheckEncryptionKey } from "@/hooks/check-encryptionkey"; import { useProfileUrl } from "@/hooks/useProfileUrl"; +import checkAndSaveKeys from "@/helpers/checkAndSaveKeys"; + import { useSearchSheet } from "@/stores/sheets-store"; const Page = () => { const hasEncryptionKey = useCheckEncryptionKey(); const deleteMessagesModal = useDeleteModal(); - const { data: session, status } = useSession(); + const { data: session, status, update } = useSession(); + + useEffect(() => { + const generateKeysIfNeeded = async () => { + if (!hasEncryptionKey) { + try { + // checks and generates key and save in IndexDB + const success = await checkAndSaveKeys(); + if (success) { + await update({ + type: "change_key", + key: true, + }); + window.location.reload(); + } else { + toast.error("Error", { + description: "Failed to auto generate keys", + }); + } + } catch (error) { + toast.error("Error", { + description: "An unexpected error occurred while generating keys", + }); + } + } + }; + + generateKeysIfNeeded(); + }, [hasEncryptionKey, update]); const queryClient = useQueryClient(); const searchSheet = useSearchSheet(); @@ -110,8 +148,8 @@ const Page = () => { <>
- {!user.hasEncryptionKey && } - {!hasEncryptionKey && } + {session && !user.hasEncryptionKey && } + {session && !hasEncryptionKey && }

Hi {user.username},

diff --git a/src/app/(auth)/sign-in/page.tsx b/src/app/(auth)/sign-in/page.tsx index fec56cf..fe9e26f 100644 --- a/src/app/(auth)/sign-in/page.tsx +++ b/src/app/(auth)/sign-in/page.tsx @@ -24,6 +24,7 @@ import { Eye, EyeOff } from "lucide-react"; import { Loader2 } from "lucide-react"; // Import Loader component import LoaderOverlay from "@/components/Loader"; import Navbar from "@/components/Navbar"; +import useCheckAndSaveKeys from "@/helpers/checkAndSaveKeys"; const Page = () => { const router = useRouter(); @@ -85,7 +86,6 @@ const Page = () => { {showLoaderOverlay && } {/* Outer container */}
-
-
Don{"'"}t have an account?
- - Sign Up - -
-
- Forgot Password? -
-
+
+
Don{"'"}t have an account?
+ + Sign Up + +
+
+ Forgot Password? +
+
{/* Back to Home Button */}
diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f1b252c..28daf4d 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,6 +9,7 @@ import { authOptions } from "./api/auth/[...nextauth]/options"; import Modals from "@/context/ModalProvider"; import QueryProvider from "@/context/QueryProvider"; import NextTopLoader from "nextjs-toploader"; +import Script from "next/script"; const inter = Inter({ subsets: ["latin"] }); @@ -27,11 +28,12 @@ export default async function RootLayout({ children: React.ReactNode; }>) { const session = await getServerSession(authOptions); + return ( <> - - + + +