From e93021b13410e75facb38a494ea56a28a6cdd623 Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 22:39:20 +0700
Subject: [PATCH 50/80] Simplify error code
---
src/app/not-found.tsx | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/app/not-found.tsx b/src/app/not-found.tsx
index 3d77a94..89048af 100644
--- a/src/app/not-found.tsx
+++ b/src/app/not-found.tsx
@@ -1,6 +1,7 @@
import Link from "next/link";
function NotFound() {
+ console.log("Not Found");
return (
-
- Error 404: Not Found
-
+
404
The file or folder you are trying to access does
not exist or has been deleted.
From e3f35643135d51b292f4debaef038d97c67a0b7f Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 22:39:49 +0700
Subject: [PATCH 51/80] Add not found if error code 404
---
src/app/[...path]/page.tsx | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/app/[...path]/page.tsx b/src/app/[...path]/page.tsx
index c83b30d..b1d8276 100644
--- a/src/app/[...path]/page.tsx
+++ b/src/app/[...path]/page.tsx
@@ -1,5 +1,6 @@
import { Metadata, ResolvingMetadata } from "next";
import { cookies } from "next/headers";
+import { notFound } from "next/navigation";
import Breadcrumb from "components/compBreadcrumb";
import FileLayout from "components/compFileLayout";
@@ -119,6 +120,9 @@ async function FilePage({ params }: Props) {
if (!pathValidation.success) {
const errorData = pathValidation as API_Error;
+ if (errorData.code === 404) {
+ notFound();
+ }
const payload = handleError(errorData);
throw new Error(payload);
}
From e06acf1ed7870d0f26cbe8eb92b6343f7206b3f6 Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 22:40:01 +0700
Subject: [PATCH 52/80] Add not found if error code 404
---
src/app/page.tsx | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 389d8a2..d05d36e 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,5 +1,6 @@
import { Metadata } from "next";
import { cookies } from "next/headers";
+import { notFound } from "next/navigation";
import Breadcrumb from "components/compBreadcrumb";
import FileLayout from "components/compFileLayout";
@@ -74,6 +75,9 @@ async function RootPage() {
if (!pathValidation.success) {
const errorData = pathValidation as API_Error;
+ if (errorData.code === 404) {
+ notFound();
+ }
const payload = handleError(errorData);
throw new Error(payload);
}
From a820c746d74deeb8b3a6e9c3f354ec2e44d646d3 Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 22:53:40 +0700
Subject: [PATCH 53/80] Redirect 401 to password page instead error page
---
src/app/(__components)/compPassword.tsx | 12 ++++++--
src/app/[...path]/page.tsx | 12 +++++++-
src/app/page.tsx | 10 +++++-
src/app/password/page.tsx | 41 +++++++++++++++++++++++++
4 files changed, 71 insertions(+), 4 deletions(-)
create mode 100644 src/app/password/page.tsx
diff --git a/src/app/(__components)/compPassword.tsx b/src/app/(__components)/compPassword.tsx
index 58fcfc8..f6120b0 100644
--- a/src/app/(__components)/compPassword.tsx
+++ b/src/app/(__components)/compPassword.tsx
@@ -1,12 +1,20 @@
"use client";
+import { useRouter } from "next/navigation";
import { useState } from "react";
import passwordHash from "utils/encryptionHelper/passwordHash";
import { Constant } from "types/general/constant";
-function Password({ path }: { path: string }) {
+function Password({
+ path,
+ redirect,
+}: {
+ path: string;
+ redirect: string;
+}) {
+ const router = useRouter();
const [password, setPassword] = useState("");
const handlePasswordSubmit = (
@@ -42,7 +50,7 @@ function Password({ path }: { path: string }) {
)}; expires=${expires.toUTCString()}; path=/`;
}
- window.location.reload();
+ router.push(redirect);
};
return (
diff --git a/src/app/[...path]/page.tsx b/src/app/[...path]/page.tsx
index b1d8276..e867051 100644
--- a/src/app/[...path]/page.tsx
+++ b/src/app/[...path]/page.tsx
@@ -1,6 +1,6 @@
import { Metadata, ResolvingMetadata } from "next";
import { cookies } from "next/headers";
-import { notFound } from "next/navigation";
+import { notFound, redirect } from "next/navigation";
import Breadcrumb from "components/compBreadcrumb";
import FileLayout from "components/compFileLayout";
@@ -120,6 +120,16 @@ async function FilePage({ params }: Props) {
if (!pathValidation.success) {
const errorData = pathValidation as API_Error;
+ if (errorData.code === 401) {
+ const protectedPath = errorData.reason
+ .split('"')[1]
+ .split('"')[0];
+ redirect(
+ `/password?redirect=${params.path.join(
+ "/",
+ )}&path=${protectedPath}`,
+ );
+ }
if (errorData.code === 404) {
notFound();
}
diff --git a/src/app/page.tsx b/src/app/page.tsx
index d05d36e..cba0317 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,6 +1,6 @@
import { Metadata } from "next";
import { cookies } from "next/headers";
-import { notFound } from "next/navigation";
+import { notFound, redirect } from "next/navigation";
import Breadcrumb from "components/compBreadcrumb";
import FileLayout from "components/compFileLayout";
@@ -75,6 +75,14 @@ async function RootPage() {
if (!pathValidation.success) {
const errorData = pathValidation as API_Error;
+ if (errorData.code === 401) {
+ const protectedPath = errorData.reason
+ .split('"')[1]
+ .split('"')[0];
+ redirect(
+ `/password?redirect=/&path=${protectedPath}`,
+ );
+ }
if (errorData.code === 404) {
notFound();
}
diff --git a/src/app/password/page.tsx b/src/app/password/page.tsx
new file mode 100644
index 0000000..a987943
--- /dev/null
+++ b/src/app/password/page.tsx
@@ -0,0 +1,41 @@
+import { redirect } from "next/navigation";
+
+import CompPassword from "components/compPassword";
+
+type Props = {
+ searchParams: {
+ [key: string]: string | string[] | undefined;
+ };
+};
+function Password({ searchParams }: Props) {
+ if (
+ searchParams["redirect"] === undefined ||
+ searchParams["path"] === undefined
+ ) {
+ redirect("/");
+ }
+
+ return (
+
+ {/* Image placeholder */}
+
+ Placeholder Image
+
+
+
+
+ );
+}
+
+export default Password;
From 2392be302d6c80220e3649fd9d94ecfcbbd7102f Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 22:55:50 +0700
Subject: [PATCH 54/80] Make redirect props optional
---
src/app/(__components)/compPassword.tsx | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/app/(__components)/compPassword.tsx b/src/app/(__components)/compPassword.tsx
index f6120b0..db027e7 100644
--- a/src/app/(__components)/compPassword.tsx
+++ b/src/app/(__components)/compPassword.tsx
@@ -9,10 +9,10 @@ import { Constant } from "types/general/constant";
function Password({
path,
- redirect,
+ redirect = "/",
}: {
path: string;
- redirect: string;
+ redirect?: string;
}) {
const router = useRouter();
const [password, setPassword] = useState("");
From 4ba1b6b496d86df5f112e2546342e634bca0e2ea Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 23:04:56 +0700
Subject: [PATCH 55/80] Test pathValidation cookies
---
src/app/[...path]/page.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/app/[...path]/page.tsx b/src/app/[...path]/page.tsx
index e867051..aafe3bb 100644
--- a/src/app/[...path]/page.tsx
+++ b/src/app/[...path]/page.tsx
@@ -108,7 +108,7 @@ async function FilePage({ params }: Props) {
)}`,
{
headers: {
- Cookie: `${Constant.cookiePassword}=${passwordCookies}`,
+ Cookie: `${Constant.cookiePassword}=${passwordCookies};test=IsThisTheProblem`,
},
},
).then(
From 3ebfc9b9893c599d6205b579b3d840cab104f5d5 Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Thu, 25 May 2023 23:15:52 +0700
Subject: [PATCH 56/80] Remove set cookie
---
src/app/error.tsx | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/app/error.tsx b/src/app/error.tsx
index 9a37485..b078a50 100644
--- a/src/app/error.tsx
+++ b/src/app/error.tsx
@@ -94,7 +94,6 @@ export default function Error({