From 1ebb8d61f1a6e7ab95bbcba395a0789b18ead217 Mon Sep 17 00:00:00 2001 From: Chief Bube Date: Sun, 22 Oct 2023 23:08:34 -0700 Subject: [PATCH] fixed redirection bug --- components/_App/LeftSidebar/SidebarData.js | 2 +- middleware.js | 10 +-- next.config.js | 2 +- pages/_app.js | 9 +-- pages/auth/index.js | 5 -- pages/ecommerce.js | 2 +- pages/index.js | 94 +++------------------- 7 files changed, 20 insertions(+), 104 deletions(-) delete mode 100644 pages/auth/index.js diff --git a/components/_App/LeftSidebar/SidebarData.js b/components/_App/LeftSidebar/SidebarData.js index b6157bb..11bce30 100644 --- a/components/_App/LeftSidebar/SidebarData.js +++ b/components/_App/LeftSidebar/SidebarData.js @@ -450,7 +450,7 @@ export const SidebarData = [ }, { title: "Authentication", - path: "/auth/login/", + path: "/auth/", icon: , iconClosed: , iconOpened: , diff --git a/middleware.js b/middleware.js index f2e44be..a8c1570 100644 --- a/middleware.js +++ b/middleware.js @@ -13,13 +13,13 @@ export async function middleware(req, next) { const { origin, pathname } = req.nextUrl; - try { - console.log("Test path", pathname, origin); + // console.log("Test path", pathname, origin); if (token) { // Redirect to the home page if already authenticated - NextResponse.redirect(new URL("/"), { status: 201 }); - next(); + NextResponse.redirect(new URL(pathname, origin), { status: 302 }); + // Continue with the request if authenticated + return NextResponse.next(); } if ( @@ -43,8 +43,6 @@ export async function middleware(req, next) { // }); // } - // Continue with the request if authenticated - return NextResponse.next(); } catch (error) { console.error("Error during authentication check:", error); return NextResponse.error(); diff --git a/next.config.js b/next.config.js index 16157a9..c538366 100644 --- a/next.config.js +++ b/next.config.js @@ -14,7 +14,7 @@ const nextConfig = { i18n: { locales: ['en', 'ar'], defaultLocale: 'en', - }, + } } module.exports = nextConfig diff --git a/pages/_app.js b/pages/_app.js index d21f59a..c663c75 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -16,18 +16,15 @@ import theme from "../styles/theme"; import { ThemeProvider, CssBaseline } from "@mui/material"; import Layout from "@/components/_App/Layout"; -import AuthRoute from "middlewares/AuthRoute"; function MyApp({ Component, pageProps }) { return ( <> - {/* */} - - - - {/* */} + + + ); diff --git a/pages/auth/index.js b/pages/auth/index.js deleted file mode 100644 index 030724c..0000000 --- a/pages/auth/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import SignInForm from "@/components/Authentication/SignInForm"; - -export default function Index() { - return ; -} diff --git a/pages/ecommerce.js b/pages/ecommerce.js index 54720af..73e51dc 100644 --- a/pages/ecommerce.js +++ b/pages/ecommerce.js @@ -16,7 +16,7 @@ import TeamMembersList from "@/components/Dashboard/eCommerce/TeamMembersList"; import BestSellingProducts from "@/components/Dashboard/eCommerce/BestSellingProducts"; import LiveVisitsOnOurSite from "@/components/Dashboard/eCommerce/LiveVisitsOnOurSite"; -export default function eCommerce() { +export default function ECommerce() { return ( <> {/* Page title */} diff --git a/pages/index.js b/pages/index.js index 3b6cdf0..ec9013d 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,86 +1,12 @@ -import React from "react"; -import Grid from "@mui/material/Grid"; -import Link from "next/link"; -import styles from "@/styles/PageTitle.module.css"; -import Features from "@/components/Dashboard/eCommerce/Features"; -import Ratings from "@/components/Dashboard/eCommerce/Ratings"; -import AudienceOverview from "@/components/Dashboard/eCommerce/AudienceOverview"; -import VisitsByDay from "@/components/Dashboard/eCommerce/VisitsByDay"; -import Impressions from "@/components/Dashboard/eCommerce/Impressions"; -import ActivityTimeline from "@/components/Dashboard/eCommerce/ActivityTimeline"; -import RevenuStatus from "@/components/Dashboard/eCommerce/RevenuStatus"; -import SalesByCountries from "@/components/Dashboard/eCommerce/SalesByCountries"; -import NewCustomers from "@/components/Dashboard/eCommerce/NewCustomers"; -import RecentOrders from "@/components/Dashboard/eCommerce/RecentOrders"; -import TeamMembersList from "@/components/Dashboard/eCommerce/TeamMembersList"; -import BestSellingProducts from "@/components/Dashboard/eCommerce/BestSellingProducts"; -import LiveVisitsOnOurSite from "@/components/Dashboard/eCommerce/LiveVisitsOnOurSite"; -import AuthRoute from "middlewares/AuthRoute"; +import { useRouter } from "next/router"; +import ECommerce from "./ecommerce"; -export default function MainPage() { - return ( - <> - {/* Page title */} -
-

eCommerce

-
    -
  • - Dashboard -
  • -
  • eCommerce
  • -
-
- - - {/* Features */} - - {/* AudienceOverview */} - - - - {/* VisitsByDay */} - - - - {/* Impressions */} - +export default function Home() { + const router = useRouter(); - {/* ActivityTimeline */} - - - - {/* RevenuStatus */} - - - - - - {/* Ratings */} - - {/* LiveVisitsOnOurSite */} - - {/* SalesByLocations */} - - {/* NewCustomers */} - - - - {/* Recent Orders */} - - - - {/* TeamMembersList */} - - - - {/* BestSellingProducts */} - - - - - ); -} \ No newline at end of file + console.log("Check pathname: " + router.pathname) + + if (router.pathname === "/") { + return ; + } +}