diff --git a/components/Authentication/SignInForm.js b/components/Authentication/SignInForm.js
index 29c3668..33f7c58 100644
--- a/components/Authentication/SignInForm.js
+++ b/components/Authentication/SignInForm.js
@@ -1,6 +1,6 @@
-import React, { useState } from "react";
+import React, { useEffect, useState } from "react";
import { useRouter } from "next/router";
-import { setCookie } from 'cookies-next';
+import { setCookie } from "cookies-next";
import Link from "next/link";
import Grid from "@mui/material/Grid";
import LoadingButton from "@mui/lab/LoadingButton";
@@ -79,9 +79,17 @@ const SignInForm = () => {
}
// Store the token in cookies
- await setCookie("cmc-token", res.token);
- router.push("/");
+ // Calculate the expiration time in 24 hours
+ const expirationDate = new Date();
+ expirationDate.setTime(expirationDate.getTime() + 24 * 60 * 60 * 1000); // 24 hours in milliseconds
+ const cookieOptions = {
+ expires: expirationDate,
+ httpOnly: true, // Make the cookie accessible only via HTTP (recommended for security)
+ };
+
+ await setCookie("cmc-token", res.token);
+ router.push("/");
console.log(res);
} catch (error) {
@@ -100,6 +108,11 @@ const SignInForm = () => {
setShowPassword(!showPassword);
};
+ useEffect(() => {
+ // Prefetch the dashboard
+ router.prefetch("/");
+ });
+
return (
<>
diff --git a/components/_App/Layout.js b/components/_App/Layout.js
index edca465..1736b2a 100644
--- a/components/_App/Layout.js
+++ b/components/_App/Layout.js
@@ -20,14 +20,11 @@ const Layout = ({ children }) => {
useEffect(() => {
const authenticationPages = [
- // "/",
- "/auth",
"/auth/login",
"/auth/sign-up",
"/auth/forgot-password",
"/auth/lock-screen",
"/auth/confirm-mail",
- "/auth/logout",
];
setIsAuthenticationPage(authenticationPages.includes(router.pathname));
@@ -38,8 +35,8 @@ const Layout = ({ children }) => {
const title = isAuthenticationPage ? "CMC - auth" : "CMC - dashboard";
const mainWrapper = {
- paddingLeft: typeof window !== "undefined" && isAuthenticationPage && "0"
- }
+ paddingLeft: typeof window !== "undefined" && isAuthenticationPage && "0",
+ };
return (
<>
@@ -65,7 +62,9 @@ const Layout = ({ children }) => {
{children}
- {!isAuthenticationPage && }
+ {!isAuthenticationPage && router.pathname !== "/auth/logout" && (
+
+ )}
diff --git a/components/_App/LeftSidebar/SidebarData.js b/components/_App/LeftSidebar/SidebarData.js
index 11bce30..a74dff5 100644
--- a/components/_App/LeftSidebar/SidebarData.js
+++ b/components/_App/LeftSidebar/SidebarData.js
@@ -6,6 +6,7 @@ import LayersIcon from "@mui/icons-material/Layers";
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import LockIcon from "@mui/icons-material/Lock";
+import LogoutIcon from "@mui/icons-material/Logout";
import SettingsIcon from "@mui/icons-material/Settings";
import PostAddIcon from "@mui/icons-material/PostAdd";
import MailOutlineIcon from "@mui/icons-material/MailOutline";
@@ -513,4 +514,9 @@ export const SidebarData = [
},
],
},
+ {
+ title: "Logout",
+ path: "/auth/logout",
+ icon: ,
+ },
];
diff --git a/components/_App/LeftSidebar/index.js b/components/_App/LeftSidebar/index.js
index bbd1224..8f5ff9d 100644
--- a/components/_App/LeftSidebar/index.js
+++ b/components/_App/LeftSidebar/index.js
@@ -1,69 +1,69 @@
-import React from 'react';
-import {
- Box
-} from "@mui/material";
+import React from "react";
+import { Box } from "@mui/material";
import { styled } from "@mui/material/styles";
-import { SidebarData } from './SidebarData';
-import SubMenu from './SubMenu';
-import Link from 'next/link';
-import ClearIcon from '@mui/icons-material/Clear';
-import IconButton from '@mui/material/IconButton';
+import { SidebarData } from "./SidebarData";
+import SubMenu from "./SubMenu";
+import Link from "next/link";
+import ClearIcon from "@mui/icons-material/Clear";
+import IconButton from "@mui/material/IconButton";
const SidebarNav = styled("nav")(({ theme }) => ({
- background: '#fff',
+ background: "#fff",
boxShadow: "0px 4px 20px rgba(47, 143, 232, 0.07)",
- width: '300px',
- padding: '30px 10px',
- height: '100vh',
- display: 'flex',
- justifyContent: 'center',
- position: 'fixed',
+ width: "300px",
+ padding: "30px 10px",
+ height: "100vh",
+ display: "flex",
+ justifyContent: "center",
+ position: "fixed",
top: 0,
left: 0,
- transition: '350ms',
- zIndex: '10',
- overflowY: 'auto'
+ transition: "350ms",
+ zIndex: "10",
+ overflowY: "auto",
}));
-
+
const SidebarWrap = styled("div")(({ theme }) => ({
- width: '100%'
+ width: "100%",
}));
const Sidebar = ({ toggleActive }) => {
return (
<>
-
+
-
-
-
+
{/* For Dark Variation */}
-
-
diff --git a/middleware.js b/middleware.js
index a8c1570..2f412c3 100644
--- a/middleware.js
+++ b/middleware.js
@@ -32,17 +32,6 @@ export async function middleware(req, next) {
});
}
- // Add authentication logic here (verify the token, etc.)
- // const isAuthenticated = verifyToken(token);
- // const isAuthenticated = hasCookie("cmc-token", { req });
-
- // if (!isAuthenticated) {
- // // Handle unauthenticated users
- // return NextResponse.error(new Error("Authentication failed"), {
- // status: 401,
- // });
- // }
-
} catch (error) {
console.error("Error during authentication check:", error);
return NextResponse.error();
@@ -54,12 +43,7 @@ export const config = {
};
const authenticationPages = [
- // "/",
- "/auth",
"/auth/login",
"/auth/sign-up",
- "/auth/forgot-password",
- "/auth/lock-screen",
- "/auth/confirm-mail",
"/auth/logout",
];
diff --git a/pages/auth/logout.js b/pages/auth/logout.js
index f4b6894..966057f 100644
--- a/pages/auth/logout.js
+++ b/pages/auth/logout.js
@@ -1,8 +1,16 @@
+import { useRouter } from 'next/router'
import { Typography } from "@mui/material";
import { Box } from "@mui/system";
import Button from "@mui/material/Button";
+import LogoutIcon from "@mui/icons-material/Logout";
+import { deleteCookie } from "cookies-next";
export default function Logout() {
+ const router = useRouter()
+ const handleLogout = () => {
+ deleteCookie("cmc-token");
+ router.push("/auth/login")
+ };
return (
<>
@@ -20,51 +28,51 @@ export default function Logout() {
maxWidth: "510px",
ml: "auto",
mr: "auto",
- textAlign: "center"
+ textAlign: "center",
}}
className="bg-black"
>
-
-
-
+
- You are Logged Out
-
-
-
- Thank you for using Admash admin template
+ Would you like to sign out?
- Sign In
+ Sign Out