Added Logout Option and prefetch for the dashboard
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user