From a848d4dcb506dc489af6b1d6347fde1a14a0b8f4 Mon Sep 17 00:00:00 2001
From: Rafi Arrafif <rafiarrafif05@gmail.com>
Date: Sun, 17 Aug 2025 22:50:24 +0700
Subject: [PATCH] :sparkles: creating login popup security check

Perform security checks on the login popup to minimize bugs in unexpected situations.
---
 app/(auth)/login/metadata.tsx              |  5 +++
 app/(auth)/login/page.tsx                  | 11 ++++++
 features/auth/pages/LoginPage.tsx          | 40 ++++++++++++++++++++++
 features/auth/ui/Login.tsx                 |  7 ++++
 features/auth/ui/SecurityCheckup.tsx       | 17 +++++++++
 features/auth/ui/SecurityCheckupFailed.tsx | 19 ++++++++++
 shared/config/routes.ts                    |  4 +--
 widgets/navbar/ui/LoginAndSignup.tsx       | 12 +++++--
 widgets/navbar/ui/Navbar.tsx               |  2 +-
 9 files changed, 112 insertions(+), 5 deletions(-)
 create mode 100644 app/(auth)/login/metadata.tsx
 create mode 100644 app/(auth)/login/page.tsx
 create mode 100644 features/auth/pages/LoginPage.tsx
 create mode 100644 features/auth/ui/Login.tsx
 create mode 100644 features/auth/ui/SecurityCheckup.tsx
 create mode 100644 features/auth/ui/SecurityCheckupFailed.tsx

diff --git a/app/(auth)/login/metadata.tsx b/app/(auth)/login/metadata.tsx
new file mode 100644
index 0000000..3ca9314
--- /dev/null
+++ b/app/(auth)/login/metadata.tsx
@@ -0,0 +1,5 @@
+import { Metadata } from "next";
+
+export const metadata: Metadata = {
+  title: "Login | Nounoz TV",
+};
diff --git a/app/(auth)/login/page.tsx b/app/(auth)/login/page.tsx
new file mode 100644
index 0000000..71628a2
--- /dev/null
+++ b/app/(auth)/login/page.tsx
@@ -0,0 +1,11 @@
+import LoginPage from "@/features/auth/pages/LoginPage";
+import { metadata } from "./metadata";
+export { metadata };
+
+import React from "react";
+
+const page = () => {
+  return <LoginPage />;
+};
+
+export default page;
diff --git a/features/auth/pages/LoginPage.tsx b/features/auth/pages/LoginPage.tsx
new file mode 100644
index 0000000..fbe1f0c
--- /dev/null
+++ b/features/auth/pages/LoginPage.tsx
@@ -0,0 +1,40 @@
+"use client";
+
+import { redirect } from "next/navigation";
+import React, { useEffect, useState } from "react";
+import Login from "@/features/auth/ui/Login";
+import SecurityCheckup from "@/features/auth/ui/SecurityCheckup";
+import SecurityCheckupFailed from "@/features/auth/ui/SecurityCheckupFailed";
+
+const LoginPage = () => {
+  const componentFlowList = {
+    securityCheckup: <SecurityCheckup />,
+    securityCheckupFailed: <SecurityCheckupFailed />,
+    SecurityCheckupSuccessed: <Login />,
+  };
+
+  const [componentFlow, setComponentFlow] = useState(
+    componentFlowList.securityCheckup
+  );
+
+  useEffect(() => {
+    if (window.opener) {
+      setComponentFlow(componentFlowList.SecurityCheckupSuccessed);
+    } else {
+      setComponentFlow(componentFlowList.securityCheckupFailed);
+
+      const timer = setTimeout(() => {
+        redirect("/");
+      }, 5000);
+      return () => clearTimeout(timer);
+    }
+  }, []);
+
+  return (
+    <>
+      <main>{componentFlow}</main>
+    </>
+  );
+};
+
+export default LoginPage;
diff --git a/features/auth/ui/Login.tsx b/features/auth/ui/Login.tsx
new file mode 100644
index 0000000..667db12
--- /dev/null
+++ b/features/auth/ui/Login.tsx
@@ -0,0 +1,7 @@
+import React from "react";
+
+const Login = () => {
+  return <div>This is login flow</div>;
+};
+
+export default Login;
diff --git a/features/auth/ui/SecurityCheckup.tsx b/features/auth/ui/SecurityCheckup.tsx
new file mode 100644
index 0000000..d778297
--- /dev/null
+++ b/features/auth/ui/SecurityCheckup.tsx
@@ -0,0 +1,17 @@
+import React from "react";
+
+const SecurityCheckup = () => {
+  return (
+    <div className="flex justify-center">
+      <div className="max-w-[60vh]">
+        <h1 className="mt-[20vh] text-2xl text-center">Please wait...</h1>
+        <p className="mt-4 text-sm text-center text-neutral-400">
+          We want to ensure a secure authentication environment before
+          proceeding for your safety.
+        </p>
+      </div>
+    </div>
+  );
+};
+
+export default SecurityCheckup;
diff --git a/features/auth/ui/SecurityCheckupFailed.tsx b/features/auth/ui/SecurityCheckupFailed.tsx
new file mode 100644
index 0000000..b1b195b
--- /dev/null
+++ b/features/auth/ui/SecurityCheckupFailed.tsx
@@ -0,0 +1,19 @@
+import React from "react";
+
+const SecurityCheckupFailed = () => {
+  return (
+    <div className="flex justify-center">
+      <div className="max-w-[60vh]">
+        <h1 className="mt-[20vh] text-2xl text-center text-red-400">
+          Your browser is not secure
+        </h1>
+        <p className="mt-4 text-sm text-center text-neutral-400">
+          Sorry, we had to stop the authentication process and return you to the
+          home page because your browser environment is not secure.
+        </p>
+      </div>
+    </div>
+  );
+};
+
+export default SecurityCheckupFailed;
diff --git a/shared/config/routes.ts b/shared/config/routes.ts
index 203aa79..d822bec 100644
--- a/shared/config/routes.ts
+++ b/shared/config/routes.ts
@@ -1,7 +1,7 @@
 export const routes = {
   home: "/",
-  login: "/log-in",
-  signup: "/sign-up",
+  login: "/login",
+  signup: "/signup",
   explore: "/explore",
   trending: "/trending",
   genres: "/genres",
diff --git a/widgets/navbar/ui/LoginAndSignup.tsx b/widgets/navbar/ui/LoginAndSignup.tsx
index ee602b4..baa4166 100644
--- a/widgets/navbar/ui/LoginAndSignup.tsx
+++ b/widgets/navbar/ui/LoginAndSignup.tsx
@@ -5,12 +5,20 @@ import { Button, Link, NavbarItem } from "@heroui/react";
 import React from "react";
 
 const LoginAndSignup = () => {
+  const openLoginPopup = (e: any) => {
+    window.open(routes.login, "popup", "width=500,height=600");
+  };
   return (
     <>
       <NavbarItem className="hidden lg:flex">
-        <Link href={routes.login} className="font-medium">
+        <Button
+          color="primary"
+          variant="light"
+          className="font-medium"
+          onPress={openLoginPopup}
+        >
           Login
-        </Link>
+        </Button>
       </NavbarItem>
       <NavbarItem>
         <Button
diff --git a/widgets/navbar/ui/Navbar.tsx b/widgets/navbar/ui/Navbar.tsx
index 6aa61c6..c5c9587 100644
--- a/widgets/navbar/ui/Navbar.tsx
+++ b/widgets/navbar/ui/Navbar.tsx
@@ -86,7 +86,7 @@ const NavbarUI = () => {
         })}
       </NavbarContent>
 
-      <NavbarContent justify="end">
+      <NavbarContent justify="end" className="gap-1">
         <LoginAndSignup />
       </NavbarContent>
 
