fixed redirection bug #10

Merged
ameye merged 1 commits from adding-login into master 2023-10-23 11:00:30 +00:00
7 changed files with 20 additions and 104 deletions
+1 -1
View File
@@ -450,7 +450,7 @@ export const SidebarData = [
},
{
title: "Authentication",
path: "/auth/login/",
path: "/auth/",
icon: <LockIcon />,
iconClosed: <KeyboardArrowRightIcon />,
iconOpened: <KeyboardArrowDownIcon />,
+4 -6
View File
@@ -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();
+1 -1
View File
@@ -14,7 +14,7 @@ const nextConfig = {
i18n: {
locales: ['en', 'ar'],
defaultLocale: 'en',
},
}
}
module.exports = nextConfig
+3 -6
View File
@@ -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 (
<>
<ThemeProvider theme={theme}>
<CssBaseline />
{/* <AuthRoute> */}
<Layout>
<Component {...pageProps} />
</Layout>
{/* </AuthRoute> */}
<Layout>
<Component {...pageProps} />
</Layout>
</ThemeProvider>
</>
);
-5
View File
@@ -1,5 +0,0 @@
import SignInForm from "@/components/Authentication/SignInForm";
export default function Index() {
return <SignInForm />;
}
+1 -1
View File
@@ -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 */}
+10 -84
View File
@@ -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 */}
<div className={styles.pageTitle}>
<h1>eCommerce</h1>
<ul>
<li>
<Link href="/">Dashboard</Link>
</li>
<li>eCommerce</li>
</ul>
</div>
<Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 2 }}>
<Grid item xs={12} md={12} lg={12} xl={8}>
{/* Features */}
<Features />
{/* AudienceOverview */}
<AudienceOverview />
<Grid container columnSpacing={{ xs: 1, sm: 2, md: 2 }}>
<Grid item xs={12} md={8}>
{/* VisitsByDay */}
<VisitsByDay />
</Grid>
<Grid item xs={12} md={4}>
{/* Impressions */}
<Impressions />
export default function Home() {
const router = useRouter();
{/* ActivityTimeline */}
<ActivityTimeline />
</Grid>
<Grid item xs={12} md={12}>
{/* RevenuStatus */}
<RevenuStatus />
</Grid>
</Grid>
</Grid>
<Grid item xs={12} md={12} lg={12} xl={4}>
{/* Ratings */}
<Ratings />
{/* LiveVisitsOnOurSite */}
<LiveVisitsOnOurSite />
{/* SalesByLocations */}
<SalesByCountries />
{/* NewCustomers */}
<NewCustomers />
</Grid>
</Grid>
{/* Recent Orders */}
<RecentOrders />
<Grid
container
rowSpacing={1}
columnSpacing={{ xs: 1, sm: 1, md: 1, lg: 1, xl: 2 }}
>
<Grid item xs={12} md={12} lg={12} xl={8}>
{/* TeamMembersList */}
<TeamMembersList />
</Grid>
<Grid item xs={12} md={12} lg={12} xl={4}>
{/* BestSellingProducts */}
<BestSellingProducts />
</Grid>
</Grid>
</>
);
}
console.log("Check pathname: " + router.pathname)
if (router.pathname === "/") {
return <ECommerce />;
}
}