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 &&