Added Logout Option and prefetch for the dashboard

This commit is contained in:
2023-10-23 00:45:13 -07:00
parent c3dea8ae95
commit de57daf98a
6 changed files with 95 additions and 85 deletions
+17 -4
View File
@@ -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 (
<>
<div className={styles.authenticationBox}>