Skip to content

Commit

Permalink
Merge branch 'MitulSonagara:master' into phone
Browse files Browse the repository at this point in the history
  • Loading branch information
akash70629 authored Oct 26, 2024
2 parents e705fce + c564af8 commit 9a10936
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<!--Line-->
<img src="https://user-images.githubusercontent.com/74038190/212284100-561aa473-3905-4a80-b561-0d28506553ee.gif" width="900">

<!--Added Table to show repo statistics-->
## 📈 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) |

<!--Line-->
<img src="https://user-images.githubusercontent.com/74038190/212284100-561aa473-3905-4a80-b561-0d28506553ee.gif" width="900">

<!-- Added Hacktoberfest 2024 and GSSoc Extended 2024 banners -->
### This project is now OFFICIALLY accepted for

Expand Down
4 changes: 2 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
48 changes: 43 additions & 5 deletions src/app/(app)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -110,8 +148,8 @@ const Page = () => {
<>
<Navbar />
<div className="my-8 mt-10 mx-4 md:mx-8 lg:mx-auto p-6 rounded w-screen max-w-6xl">
{!user.hasEncryptionKey && <GenerateEncryptionAlert />}
{!hasEncryptionKey && <AddEncryptionAlert />}
{session && !user.hasEncryptionKey && <GenerateEncryptionAlert />}
{session && !hasEncryptionKey && <AddEncryptionAlert />}
<h1 className="text-4xl font-bold mb-4">Hi {user.username},</h1>
<div className="mb-4">
<div className="mt-2 border p-2 rounded-2xl flex items-center gap-3">
Expand Down
28 changes: 14 additions & 14 deletions src/app/(auth)/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -85,7 +86,6 @@ const Page = () => {
{showLoaderOverlay && <LoaderOverlay />}
{/* Outer container */}
<div

className="mt-10 w-full bg-gray-200
dark:bg-transparent max-w-md border-gray-200
Expand Down Expand Up @@ -178,19 +178,19 @@ const Page = () => {

{/* Sign Up and Forgot Password */}
<div className="flex justify-between items-center mt-2">
<div className="text-sm">
<div>Don{"'"}t have an account?</div>
<Link
href="/sign-up"
className="text-blue-600 hover:text-blue-800"
>
Sign Up
</Link>
</div>
<div className="text-red-500 text-sm">
<Link href="/forgot-password/email">Forgot Password?</Link>
</div>
</div>
<div className="text-sm">
<div>Don{"'"}t have an account?</div>
<Link
href="/sign-up"
className="text-blue-600 hover:text-blue-800"
>
Sign Up
</Link>
</div>
<div className="text-red-500 text-sm">
<Link href="/forgot-password/email">Forgot Password?</Link>
</div>
</div>

{/* Back to Home Button */}
<div className="text-center mt-4">
Expand Down
29 changes: 25 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"] });

Expand All @@ -27,11 +28,12 @@ export default async function RootLayout({
children: React.ReactNode;
}>) {
const session = await getServerSession(authOptions);

return (
<>
<html lang="en" suppressHydrationWarning>
<QueryProvider>
<AuthProvider session={session}>
<AuthProvider session={session}>
<QueryProvider>
<body className={inter.className}>
<ThemeProvider
attribute="class"
Expand All @@ -47,10 +49,29 @@ export default async function RootLayout({
{children}
<Toaster richColors expand={true} />
<Modals />
<Script
id="chatbase-full-embed"
strategy="beforeInteractive"
dangerouslySetInnerHTML={{
__html: `
window.embeddedChatbotConfig = {
chatbotId: "R-6622MFJRjEGXxJTsXD4",
domain: "www.chatbase.co"
};
(function() {
var s = document.createElement("script");
s.src = "https://www.chatbase.co/embed.min.js";
s.defer = true;
document.body.appendChild(s);
})();
`,
}}
/>
</ThemeProvider>
</body>
</AuthProvider>
</QueryProvider>
</QueryProvider>
</AuthProvider>
</html>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Navbar = () => {
const { data: session, status } = useSession();
const loading = status === "loading";
const loggedIn = !!session;

const usernameChangeModal = useUsernameModal();
const changeEncryptionKeyModal = useChangeEncryptionKeyModal();

Expand Down
2 changes: 1 addition & 1 deletion src/components/ScrollToTopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ScrollToTopButton = () => {
}, []);

return (
<div className="fixed bottom-8 right-8 z-50">
<div className="fixed bottom-[80px] right-5 z-50">
{isVisible && (
<button
onClick={scrollToTop}
Expand Down
35 changes: 35 additions & 0 deletions src/helpers/checkAndSaveKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use client"

import { savePrivateKey } from "@/lib/indexedDB";
import { IGenerateKeyWorker } from "@/types/comlinkWorkerTypes";
import axios from "axios";
import { wrap } from "comlink";

export default async function checkAndSaveKeys() {


try {
console.log("HITTING!")
const worker = new Worker(
new URL("../workers/crypto.ts", import.meta.url),
{
type: "module",
}
);

const { generateKeyPair } = wrap<IGenerateKeyWorker>(worker);

const { publicKey, privateKey } = await generateKeyPair();
worker.terminate();

await savePrivateKey(privateKey);
// Send public key to server to store it
const response = await axios.post("/api/savePublicKey", { publicKey });
return true;

} catch (error) {
console.error("Error auto generating keys:", error);

return false;
}
}

0 comments on commit 9a10936

Please sign in to comment.