Skip to content

Commit

Permalink
Merge pull request #885 from acm-ucr/shahdivyank/remove_protected_page
Browse files Browse the repository at this point in the history
fix error
  • Loading branch information
shahdivyank authored Nov 13, 2023
2 parents 75afff6 + 6de5d79 commit 89f8a04
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 209 deletions.
10 changes: 2 additions & 8 deletions src/app/error.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
"use client";
import Error from "@/components/dynamic/Error";

export default function InternalError() {
return (
<Error
code="500"
error="Internal Server Error"
message="Please contact the web development team for assistance."
/>
);
export default function InternalError({ error: { code, name, message } }) {
return <Error code={code} error={name} message={message} />;
}
14 changes: 2 additions & 12 deletions src/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import "bootstrap/dist/css/bootstrap.min.css";
import { Poppins } from "next/font/google";
import { SessionProvider } from "next-auth/react";
import { Toaster } from "react-hot-toast";
import ProtectedPage from "@/components/dynamic/ProtectedPage";
import Navigation from "@/components/dynamic/Navigation";
import { usePathname } from "next/navigation";

const poppins = Poppins({
subsets: ["latin"],
Expand All @@ -17,10 +14,6 @@ const poppins = Poppins({
});

export default function RootLayout({ children, session }) {
const pathName = usePathname();

const navigation = RegExp(/user\/|admin\//).test(pathName);

return (
<html lang="en" className="h-full">
<body className={`${poppins.variable} flex flex-col lg:flex-row h-full`}>
Expand All @@ -30,11 +23,8 @@ export default function RootLayout({ children, session }) {
className="h-full"
>
<div className="flex w-full">
{navigation && <Navigation />}
<ProtectedPage>
<Toaster />
{children}
</ProtectedPage>
<Toaster />
{children}
</div>
</SessionProvider>
</body>
Expand Down
14 changes: 5 additions & 9 deletions src/components/dynamic/ProtectedPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { signIn, useSession } from "next-auth/react";
import Loading from "@/components/dynamic/Loading";
import { usePathname } from "next/navigation";
import RELEASES from "@/data/Releases";
import { ROUTES } from "@/data/ProtectedRoutes";
import Fault from "@/utils/error";
import Navigation from "@/components/dynamic/Navigation";

const ProtectedPage = ({ children }) => {
const ProtectedPage = ({ children, restrictions, title }) => {
const { data: session, status } = useSession();
const [confirmed, setConfirmed] = useState(false);

const pathName = usePathname();
const restrictions = ROUTES[pathName].restrictions;
const title = ROUTES[pathName].title;
const bypass = ROUTES[pathName].bypass;

useEffect(() => {
if (bypass) {
setConfirmed(true);
return;
}
if (RELEASES.DYNAMIC[pathName] > new Date()) {
throw new Fault(
423,
Expand Down Expand Up @@ -55,12 +48,15 @@ const ProtectedPage = ({ children }) => {
setConfirmed(true);
}, [status]);

const navigation = RegExp(/user\/|admin\//).test(pathName);

return (
<>
{status === "loading" && <Loading />}
{confirmed && (
<>
<title>{title}</title>
{navigation && <Navigation />}
<div className="flex justify-center items-start w-full bg-hackathon-page h-screen pt-12 lg:pt-0 z-0">
<div className={`w-[96%] h-full`}>{children}</div>
</div>
Expand Down
180 changes: 0 additions & 180 deletions src/data/ProtectedRoutes.js

This file was deleted.

0 comments on commit 89f8a04

Please sign in to comment.