Compare commits
22 Commits
auth-wallpaper
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f431e1e8d6 | |||
| e0fb79f2c9 | |||
| d7fea3c760 | |||
| 5502bcd1ae | |||
| 7634aaa225 | |||
| de57daf98a | |||
| c3dea8ae95 | |||
| 1ebb8d61f1 | |||
| f67d33396e | |||
| 5e3e17e7c2 | |||
| 1f4cabe8b9 | |||
| eceb3178fd | |||
| 5f65d45c9c | |||
| c48c959749 | |||
| ed2ebe41e6 | |||
| 07337a6cfc | |||
| c185b6536e | |||
| 42e21d3123 | |||
| 33eefd5013 | |||
| defc3411bb | |||
| 8bf86c8d35 | |||
| a84cdcb886 |
@@ -104,7 +104,7 @@ const ForgotPasswordForm = () => {
|
|||||||
|
|
||||||
<Box as="div" textAlign="center" mt="20px">
|
<Box as="div" textAlign="center" mt="20px">
|
||||||
<Link
|
<Link
|
||||||
href="/auth/sign-in/"
|
href="/auth/login/"
|
||||||
className="primaryColor text-decoration-none"
|
className="primaryColor text-decoration-none"
|
||||||
>
|
>
|
||||||
<i className="ri-arrow-left-s-line"></i> Back to Sign in
|
<i className="ri-arrow-left-s-line"></i> Back to Sign in
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import Link from "next/link";
|
import { useRouter } from "next/router";
|
||||||
|
import { setCookie } from "cookies-next";
|
||||||
|
import { useSnackbar } from "notistack";
|
||||||
import Grid from "@mui/material/Grid";
|
import Grid from "@mui/material/Grid";
|
||||||
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { Typography } from "@mui/material";
|
import { Typography } from "@mui/material";
|
||||||
import { Box } from "@mui/system";
|
import { Box } from "@mui/system";
|
||||||
@@ -10,24 +13,141 @@ import Button from "@mui/material/Button";
|
|||||||
import Visibility from "@mui/icons-material/Visibility";
|
import Visibility from "@mui/icons-material/Visibility";
|
||||||
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
import VisibilityOff from "@mui/icons-material/VisibilityOff";
|
||||||
import styles from "./signinform.module.css";
|
import styles from "./signinform.module.css";
|
||||||
import WrenchBoardLogo from "@/public/images/logos/wrenchboard-logo.png";
|
import Fetcher from "services/Fetcher";
|
||||||
|
import { useUserProfile } from "contexts/userProfileContext";
|
||||||
|
|
||||||
const SignInForm = () => {
|
const SignInForm = () => {
|
||||||
const handleSubmit = (event) => {
|
const { state, dispatch } = useUserProfile();
|
||||||
event.preventDefault();
|
|
||||||
const data = new FormData(event.currentTarget);
|
// Define and initialize state variables
|
||||||
console.log({
|
const [formValues, setFormValues] = useState({
|
||||||
email: data.get("email"),
|
email: "",
|
||||||
password: data.get("password"),
|
password: "",
|
||||||
});
|
});
|
||||||
|
const [errorHandlers, setErrorHandlers] = useState({
|
||||||
|
email: false,
|
||||||
|
password: false,
|
||||||
|
});
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [errMsg, setErrMsg] = useState("");
|
||||||
|
|
||||||
|
// Create instances of external services
|
||||||
|
const api = new Fetcher();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
// Access the Snackbar notification function
|
||||||
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
|
// Handle changes in the input fields
|
||||||
|
const handleChange = (event) => {
|
||||||
|
setFormValues({ ...formValues, [event.target.name]: event.target.value });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle form submission
|
||||||
|
const handleSubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const { email, password } = formValues;
|
||||||
|
|
||||||
|
// Validate the form fields
|
||||||
|
if (email === "" && password === "") {
|
||||||
|
setErrorHandlers({ ...errorHandlers, email: true, password: true });
|
||||||
|
setErrMsg("all fields are required");
|
||||||
|
setTimeout(() => {
|
||||||
|
setErrorHandlers({ ...errorHandlers, email: false, password: false });
|
||||||
|
setErrMsg("");
|
||||||
|
}, 2000);
|
||||||
|
return;
|
||||||
|
} else if (email === "") {
|
||||||
|
setErrorHandlers({ ...errorHandlers, email: true });
|
||||||
|
setErrMsg("email field is required");
|
||||||
|
setTimeout(() => {
|
||||||
|
setErrorHandlers({ ...errorHandlers, email: false });
|
||||||
|
setErrMsg("");
|
||||||
|
}, 2000);
|
||||||
|
return;
|
||||||
|
} else if (password === "") {
|
||||||
|
setErrorHandlers({ ...errorHandlers, password: true });
|
||||||
|
setErrMsg("password field is required");
|
||||||
|
setTimeout(() => {
|
||||||
|
setErrorHandlers({ ...errorHandlers, password: false });
|
||||||
|
setErrMsg("");
|
||||||
|
}, 2000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate the login process
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
// Prepare the login request data
|
||||||
|
const data = {
|
||||||
|
username: email,
|
||||||
|
password,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send the login request to the server
|
||||||
|
const res = await api.login(data);
|
||||||
|
|
||||||
|
if (res.status === 204 || res.length === 0) {
|
||||||
|
// Handle login failure
|
||||||
|
enqueueSnackbar("Wrong Credentials", {
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the token in cookies
|
||||||
|
// 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)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Set the login token in a cookie
|
||||||
|
await setCookie("cmc-token", res.token);
|
||||||
|
|
||||||
|
const userProfileData = res.profile;
|
||||||
|
dispatch({ type: 'SET_USER_PROFILE', payload: userProfileData });
|
||||||
|
|
||||||
|
enqueueSnackbar("Login Successful", {
|
||||||
|
variant: "success",
|
||||||
|
autoHideDuration: 4000,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Redirect the user to a new page after successful login
|
||||||
|
router.push("/");
|
||||||
|
|
||||||
|
console.log(res);
|
||||||
|
} catch (error) {
|
||||||
|
// Handle any errors that occur during login
|
||||||
|
setLoading(false);
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
// Ensure that the loading indicator is cleared after a short delay
|
||||||
|
setTimeout(() => {
|
||||||
|
setLoading(false);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define and initialize the state variable for toggling password visibility
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
|
|
||||||
|
// Toggle password visibility
|
||||||
const handleTogglePassword = () => {
|
const handleTogglePassword = () => {
|
||||||
setShowPassword(!showPassword);
|
setShowPassword(!showPassword);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Prefetch the dashboard page to optimize navigation
|
||||||
|
router.prefetch("/");
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.authenticationBox}>
|
<div className={styles.authenticationBox}>
|
||||||
@@ -57,15 +177,6 @@ const SignInForm = () => {
|
|||||||
className={styles.favicon}
|
className={styles.favicon}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{/* <Typography
|
|
||||||
as="h1"
|
|
||||||
fontSize="28px"
|
|
||||||
fontWeight="700"
|
|
||||||
mb="5px"
|
|
||||||
color="#fff"
|
|
||||||
>
|
|
||||||
Sign In{" "}
|
|
||||||
</Typography> */}
|
|
||||||
|
|
||||||
<Box component="form" noValidate onSubmit={handleSubmit}>
|
<Box component="form" noValidate onSubmit={handleSubmit}>
|
||||||
<Box
|
<Box
|
||||||
@@ -79,53 +190,43 @@ const SignInForm = () => {
|
|||||||
>
|
>
|
||||||
<Grid container alignItems="center" spacing={2}>
|
<Grid container alignItems="center" spacing={2}>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
{/* <Typography
|
|
||||||
component="label"
|
|
||||||
sx={{
|
|
||||||
fontWeight: "500",
|
|
||||||
fontSize: "14px",
|
|
||||||
mb: "10px",
|
|
||||||
display: "block",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Email
|
|
||||||
</Typography> */}
|
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
required
|
required
|
||||||
fullWidth
|
fullWidth
|
||||||
id="email"
|
id="email"
|
||||||
label="Email Address"
|
label={
|
||||||
|
errorHandlers.email && errMsg !== ""
|
||||||
|
? errMsg
|
||||||
|
: "Email Address"
|
||||||
|
}
|
||||||
|
value={formValues.email}
|
||||||
|
onChange={handleChange}
|
||||||
name="email"
|
name="email"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
InputProps={{
|
InputProps={{
|
||||||
style: { borderRadius: 8 },
|
style: { borderRadius: 8 },
|
||||||
}}
|
}}
|
||||||
sx={textFieldStyles}
|
sx={textFieldStyles}
|
||||||
|
error={errorHandlers.email}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
{/* <Typography
|
|
||||||
component="label"
|
|
||||||
sx={{
|
|
||||||
fontWeight: "500",
|
|
||||||
fontSize: "14px",
|
|
||||||
mb: "10px",
|
|
||||||
display: "block",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Password
|
|
||||||
</Typography> */}
|
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
required
|
required
|
||||||
fullWidth
|
fullWidth
|
||||||
name="password"
|
name="password"
|
||||||
label="Password"
|
label={
|
||||||
|
errorHandlers.password && errMsg !== ""
|
||||||
|
? errMsg
|
||||||
|
: "Password"
|
||||||
|
}
|
||||||
|
value={formValues.password}
|
||||||
type={showPassword ? "text" : "password"}
|
type={showPassword ? "text" : "password"}
|
||||||
id="password"
|
id="password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errorHandlers.password}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
style: { borderRadius: 8 },
|
style: { borderRadius: 8 },
|
||||||
endAdornment: (
|
endAdornment: (
|
||||||
@@ -154,26 +255,30 @@ const SignInForm = () => {
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Button
|
<Box sx={{ backgroundColor: "#4687BA" }}>
|
||||||
type="submit"
|
<LoadingButton
|
||||||
fullWidth
|
type="submit"
|
||||||
variant="contained"
|
fullWidth
|
||||||
sx={{
|
variant="contained"
|
||||||
mt: 2,
|
loading={loading}
|
||||||
backgroundColor: "#4687BA",
|
disabled={loading}
|
||||||
textTransform: "capitalize",
|
loadingIndicator="Signing in…"
|
||||||
borderRadius: "8px",
|
sx={{
|
||||||
fontWeight: "500",
|
backgroundColor: "#4687BA",
|
||||||
fontSize: "16px",
|
textTransform: "capitalize",
|
||||||
padding: "12px 10px",
|
borderRadius: "8px",
|
||||||
color: "#fff !important",
|
fontWeight: "500",
|
||||||
"&:hover": {
|
fontSize: "16px",
|
||||||
backgroundColor: "rgba(70, 135, 186, 0.8)"
|
padding: "12px 10px",
|
||||||
},
|
color: "#fff !important",
|
||||||
}}
|
"&:hover": {
|
||||||
>
|
backgroundColor: "rgba(70, 135, 186, 0.8)",
|
||||||
Sign In
|
},
|
||||||
</Button>
|
}}
|
||||||
|
>
|
||||||
|
<span>{loading ? "Signing in…" : "Sign In"}</span>
|
||||||
|
</LoadingButton>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const SignUpForm = () => {
|
|||||||
<Typography fontSize="15px" mb="30px">
|
<Typography fontSize="15px" mb="30px">
|
||||||
Already have an account?{" "}
|
Already have an account?{" "}
|
||||||
<Link
|
<Link
|
||||||
href="/auth/sign-in/"
|
href="/auth/login/"
|
||||||
className="primaryColor text-decoration-none"
|
className="primaryColor text-decoration-none"
|
||||||
>
|
>
|
||||||
Sign in
|
Sign in
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import TopNavbar from "@/components/_App/TopNavbar";
|
|||||||
import Footer from "@/components/_App/Footer";
|
import Footer from "@/components/_App/Footer";
|
||||||
import ScrollToTop from "./ScrollToTop";
|
import ScrollToTop from "./ScrollToTop";
|
||||||
import ControlPanelModal from "./ControlPanelModal";
|
import ControlPanelModal from "./ControlPanelModal";
|
||||||
import AuthRoute from "middlewares/AuthRoute";
|
|
||||||
|
|
||||||
const Layout = ({ children }) => {
|
const Layout = ({ children }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -20,20 +19,18 @@ const Layout = ({ children }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const authenticationPages = [
|
const authenticationPages = [
|
||||||
"/auth",
|
"/auth/login",
|
||||||
"/auth/sign-in",
|
|
||||||
"/auth/sign-up",
|
"/auth/sign-up",
|
||||||
"/auth/forgot-password",
|
"/auth/forgot-password",
|
||||||
"/auth/lock-screen",
|
"/auth/lock-screen",
|
||||||
"/auth/confirm-mail",
|
"/auth/confirm-mail",
|
||||||
"/auth/logout",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
setIsAuthenticationPage(authenticationPages.includes(router.pathname));
|
setIsAuthenticationPage(authenticationPages.includes(router.pathname));
|
||||||
}, [router.pathname]);
|
}, [router.pathname]);
|
||||||
|
|
||||||
// Debugging: Log the value of isAuthenticationPage
|
// Debugging: Log the value of isAuthenticationPage
|
||||||
console.log("isAuthenticationPage:", isAuthenticationPage, router.pathname);
|
// console.log("isAuthenticationPage:", isAuthenticationPage, router.pathname);
|
||||||
|
|
||||||
const title = isAuthenticationPage ? "CMC - auth" : "CMC - dashboard";
|
const title = isAuthenticationPage ? "CMC - auth" : "CMC - dashboard";
|
||||||
|
|
||||||
@@ -45,10 +42,9 @@ const Layout = ({ children }) => {
|
|||||||
</Head>
|
</Head>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={`main-wrapper-content ${active ? "active" : ""}`}
|
className={`main-wrapper-content ${active ? "active" : ""} ${
|
||||||
style={{
|
isAuthenticationPage ? "authBox" : ""
|
||||||
paddingLeft: isAuthenticationPage && "0",
|
}`}
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{!isAuthenticationPage && (
|
{!isAuthenticationPage && (
|
||||||
<>
|
<>
|
||||||
@@ -63,7 +59,9 @@ const Layout = ({ children }) => {
|
|||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!isAuthenticationPage && <Footer />}
|
{!isAuthenticationPage && router.pathname !== "/auth/logout" && (
|
||||||
|
<Footer />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ScrollToTop />
|
<ScrollToTop />
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import LayersIcon from "@mui/icons-material/Layers";
|
|||||||
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
||||||
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
|
||||||
import LockIcon from "@mui/icons-material/Lock";
|
import LockIcon from "@mui/icons-material/Lock";
|
||||||
|
import LogoutIcon from "@mui/icons-material/Logout";
|
||||||
import SettingsIcon from "@mui/icons-material/Settings";
|
import SettingsIcon from "@mui/icons-material/Settings";
|
||||||
import PostAddIcon from "@mui/icons-material/PostAdd";
|
import PostAddIcon from "@mui/icons-material/PostAdd";
|
||||||
import MailOutlineIcon from "@mui/icons-material/MailOutline";
|
import MailOutlineIcon from "@mui/icons-material/MailOutline";
|
||||||
@@ -450,7 +451,7 @@ export const SidebarData = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Authentication",
|
title: "Authentication",
|
||||||
path: "/auth/sign-in/",
|
path: "/auth/",
|
||||||
icon: <LockIcon />,
|
icon: <LockIcon />,
|
||||||
iconClosed: <KeyboardArrowRightIcon />,
|
iconClosed: <KeyboardArrowRightIcon />,
|
||||||
iconOpened: <KeyboardArrowDownIcon />,
|
iconOpened: <KeyboardArrowDownIcon />,
|
||||||
@@ -513,4 +514,9 @@ export const SidebarData = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Logout",
|
||||||
|
path: "/auth/logout",
|
||||||
|
icon: <LogoutIcon />,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,69 +1,69 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
import {
|
import { Box } from "@mui/material";
|
||||||
Box
|
|
||||||
} from "@mui/material";
|
|
||||||
import { styled } from "@mui/material/styles";
|
import { styled } from "@mui/material/styles";
|
||||||
import { SidebarData } from './SidebarData';
|
import { SidebarData } from "./SidebarData";
|
||||||
import SubMenu from './SubMenu';
|
import SubMenu from "./SubMenu";
|
||||||
import Link from 'next/link';
|
import Link from "next/link";
|
||||||
import ClearIcon from '@mui/icons-material/Clear';
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
|
||||||
const SidebarNav = styled("nav")(({ theme }) => ({
|
const SidebarNav = styled("nav")(({ theme }) => ({
|
||||||
background: '#fff',
|
background: "#fff",
|
||||||
boxShadow: "0px 4px 20px rgba(47, 143, 232, 0.07)",
|
boxShadow: "0px 4px 20px rgba(47, 143, 232, 0.07)",
|
||||||
width: '300px',
|
width: "300px",
|
||||||
padding: '30px 10px',
|
padding: "30px 10px",
|
||||||
height: '100vh',
|
height: "100vh",
|
||||||
display: 'flex',
|
display: "flex",
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
position: 'fixed',
|
position: "fixed",
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
transition: '350ms',
|
transition: "350ms",
|
||||||
zIndex: '10',
|
zIndex: "10",
|
||||||
overflowY: 'auto'
|
overflowY: "auto",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const SidebarWrap = styled("div")(({ theme }) => ({
|
const SidebarWrap = styled("div")(({ theme }) => ({
|
||||||
width: '100%'
|
width: "100%",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const Sidebar = ({ toggleActive }) => {
|
const Sidebar = ({ toggleActive }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='leftSidebarDark'>
|
<div className="leftSidebarDark">
|
||||||
<SidebarNav className="LeftSidebarNav">
|
<SidebarNav className="LeftSidebarNav">
|
||||||
<SidebarWrap>
|
<SidebarWrap>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
mb: '20px',
|
mb: "20px",
|
||||||
px: '20px',
|
px: "20px",
|
||||||
display: 'flex',
|
display: "flex",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
justifyContent: 'space-between'
|
justifyContent: "space-between",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Link href='/'>
|
<Link href="/">
|
||||||
<img
|
<img
|
||||||
src="/images/logos/wrenchboard-logo.png" alt="Logo"
|
src="/images/logos/wrenchboard-logo.png"
|
||||||
className='black-logo'
|
alt="Logo"
|
||||||
|
className="black-logo"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* For Dark Variation */}
|
{/* For Dark Variation */}
|
||||||
<img
|
<img
|
||||||
src="/images/logos/wrenchboard-logo.png" alt="Logo"
|
src="/images/logos/wrenchboard-logo.png"
|
||||||
className='white-logo'
|
alt="Logo"
|
||||||
|
className="white-logo"
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={toggleActive}
|
onClick={toggleActive}
|
||||||
size="small"
|
size="small"
|
||||||
sx={{
|
sx={{
|
||||||
background: 'rgb(253, 237, 237)',
|
background: "rgb(253, 237, 237)",
|
||||||
display: { lg: 'none' },
|
display: { lg: "none" },
|
||||||
marginLeft: "1rem"
|
marginLeft: "1rem",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ClearIcon />
|
<ClearIcon />
|
||||||
|
|||||||
@@ -17,8 +17,12 @@ import MailOutlineIcon from "@mui/icons-material/MailOutline";
|
|||||||
import ChatBubbleOutlineIcon from "@mui/icons-material/ChatBubbleOutline";
|
import ChatBubbleOutlineIcon from "@mui/icons-material/ChatBubbleOutline";
|
||||||
import AttachMoneyIcon from "@mui/icons-material/AttachMoney";
|
import AttachMoneyIcon from "@mui/icons-material/AttachMoney";
|
||||||
import Logout from "@mui/icons-material/Logout";
|
import Logout from "@mui/icons-material/Logout";
|
||||||
|
import { useUserProfile } from "contexts/userProfileContext";
|
||||||
|
|
||||||
const Profile = () => {
|
const Profile = () => {
|
||||||
|
const { state } = useUserProfile();
|
||||||
|
const userProfile = state.userProfile;
|
||||||
|
|
||||||
const [anchorEl, setAnchorEl] = React.useState(null);
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
const handleClick = (event) => {
|
const handleClick = (event) => {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// UserProfileContext.js
|
||||||
|
import { createContext, useContext, useReducer } from "react";
|
||||||
|
|
||||||
|
// Define the initial state
|
||||||
|
const initialState = {
|
||||||
|
userProfile: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the context
|
||||||
|
const UserProfileContext = createContext();
|
||||||
|
|
||||||
|
// Create a custom hook for using the context
|
||||||
|
export const useUserProfile = () => {
|
||||||
|
return useContext(UserProfileContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define a reducer function to update the context state
|
||||||
|
const userProfileReducer = (state, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "SET_USER_PROFILE":
|
||||||
|
return { ...state, userProfile: action.payload };
|
||||||
|
case "CLEAR_USER_PROFILE":
|
||||||
|
return { ...state, userProfile: null };
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create the UserProfileProvider component
|
||||||
|
export const UserProfileProvider = ({ children }) => {
|
||||||
|
const [state, dispatch] = useReducer(userProfileReducer, initialState);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<UserProfileContext.Provider value={{ state, dispatch }}>
|
||||||
|
{children}
|
||||||
|
</UserProfileContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
|
import { getCookie, hasCookie } from "cookies-next";
|
||||||
|
|
||||||
|
export async function middleware(req, next) {
|
||||||
|
const token = getCookie("cmc-token", { req }); // Access the token from cookies
|
||||||
|
|
||||||
|
const headers = new Headers(req.headers);
|
||||||
|
headers.set("X-XSS-Protection", "1; mode=block");
|
||||||
|
headers.set("X-Frame-Options", "SAMEORIGIN");
|
||||||
|
headers.set("Content-Security-Policy", "frame-ancestors 'same';");
|
||||||
|
|
||||||
|
const { origin, pathname } = req.nextUrl;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log("Test path", pathname, origin);
|
||||||
|
if (token) {
|
||||||
|
// Redirect to the home page if already authenticated
|
||||||
|
NextResponse.redirect(new URL(pathname, origin), { status: 302 });
|
||||||
|
// Continue with the request if authenticated
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!authenticationPages.includes(pathname) ||
|
||||||
|
(authenticationPages.includes(pathname) && !token)
|
||||||
|
) {
|
||||||
|
// Redirect to the login page if not authenticated
|
||||||
|
return NextResponse.redirect(new URL("/auth/login", origin), {
|
||||||
|
status: 307,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error during authentication check:", error);
|
||||||
|
return NextResponse.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: "/",
|
||||||
|
};
|
||||||
|
|
||||||
|
const authenticationPages = [
|
||||||
|
"/auth/login",
|
||||||
|
"/auth/sign-up",
|
||||||
|
"/auth/logout",
|
||||||
|
];
|
||||||
+24
-11
@@ -1,24 +1,37 @@
|
|||||||
"use client";
|
"use client"
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is used to protect routes in a web application.
|
|
||||||
* It checks if the user is authenticated and redirects them to the sign-in page if they are not.
|
|
||||||
|
|
||||||
*/
|
|
||||||
const AuthRoute = ({ children }) => {
|
const AuthRoute = ({ children }) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const token = req.cookies["cmc-token"]; // Access the token from cookies
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isAuthenticated = false; // In a real application, this would be determined based on the user's authentication status.
|
|
||||||
|
|
||||||
if (!isAuthenticated) {
|
const isAuthenticated = token ? true : false;
|
||||||
router.push("/auth/sign-in");
|
|
||||||
}
|
// if (router.pathname === "/auth/login" && isAuthenticated) {
|
||||||
}, [router]);
|
// router.push("/");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!authenticationPages.includes(router.pathname) && !isAuthenticated) {
|
||||||
|
// router.push("/auth/login");
|
||||||
|
// }
|
||||||
|
}, []);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AuthRoute;
|
export default AuthRoute;
|
||||||
|
|
||||||
|
const authenticationPages = [
|
||||||
|
// "/",
|
||||||
|
"/auth",
|
||||||
|
"/auth/login",
|
||||||
|
"/auth/sign-up",
|
||||||
|
"/auth/forgot-password",
|
||||||
|
"/auth/lock-screen",
|
||||||
|
"/auth/confirm-mail",
|
||||||
|
"/auth/logout",
|
||||||
|
];
|
||||||
+5
-1
@@ -25,6 +25,7 @@
|
|||||||
"@mui/x-date-pickers": "^5.0.12",
|
"@mui/x-date-pickers": "^5.0.12",
|
||||||
"@ramonak/react-progress-bar": "^5.0.3",
|
"@ramonak/react-progress-bar": "^5.0.3",
|
||||||
"apexcharts": "^3.36.3",
|
"apexcharts": "^3.36.3",
|
||||||
|
"bootstrap": "^5.3.2",
|
||||||
"chart.js": "^4.3.0",
|
"chart.js": "^4.3.0",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"eslint": "8.28.0",
|
"eslint": "8.28.0",
|
||||||
@@ -40,7 +41,10 @@
|
|||||||
"react-simple-maps": "^3.0.0",
|
"react-simple-maps": "^3.0.0",
|
||||||
"react-tabs": "^6.0.0",
|
"react-tabs": "^6.0.0",
|
||||||
"recharts": "^2.2.0",
|
"recharts": "^2.2.0",
|
||||||
"swiper": "^8.4.5"
|
"swiper": "^8.4.5",
|
||||||
|
"axios": "^0.24.0",
|
||||||
|
"cookies-next": "4.0.0"
|
||||||
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sass": "^1.57.1"
|
"sass": "^1.57.1"
|
||||||
|
|||||||
+39
-8
@@ -1,4 +1,5 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
|
import Head from "next/head";
|
||||||
import "../styles/remixicon.css";
|
import "../styles/remixicon.css";
|
||||||
import "react-tabs/style/react-tabs.css";
|
import "react-tabs/style/react-tabs.css";
|
||||||
import "swiper/css";
|
import "swiper/css";
|
||||||
@@ -13,21 +14,51 @@ import "../styles/rtl.css";
|
|||||||
import "../styles/dark.css";
|
import "../styles/dark.css";
|
||||||
// Theme Styles
|
// Theme Styles
|
||||||
import theme from "../styles/theme";
|
import theme from "../styles/theme";
|
||||||
|
import { SnackbarProvider } from "notistack";
|
||||||
import { ThemeProvider, CssBaseline } from "@mui/material";
|
import { ThemeProvider, CssBaseline } from "@mui/material";
|
||||||
import Layout from "@/components/_App/Layout";
|
import Layout from "@/components/_App/Layout";
|
||||||
import AuthRoute from "middlewares/AuthRoute";
|
import { UserProfileProvider } from "contexts/userProfileContext";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import { hasCookie } from "cookies-next";
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }) {
|
function MyApp({ Component, pageProps }) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const handlePopState = () => {
|
||||||
|
// Check if the user is logged in or if you need to redirect them after logout
|
||||||
|
if (!hasCookie("cmc-token")) {
|
||||||
|
router.push("/auth/login");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Attach the event handler when the component mounts
|
||||||
|
useEffect(() => {
|
||||||
|
window.onpopstate = handlePopState;
|
||||||
|
|
||||||
|
// Clean up the event handler when the component unmounts
|
||||||
|
return () => {
|
||||||
|
window.onpopstate = null;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{!hasCookie("cmc-token") && "CMC - auth"}</title>
|
||||||
|
</Head>
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<AuthRoute>
|
<UserProfileProvider>
|
||||||
<Layout>
|
<SnackbarProvider
|
||||||
<Component {...pageProps} />
|
maxSnack={3}
|
||||||
</Layout>
|
autoHideDuration={2000}
|
||||||
</AuthRoute>
|
preventDuplicate
|
||||||
|
>
|
||||||
|
<Layout>
|
||||||
|
<Component {...pageProps} />
|
||||||
|
</Layout>
|
||||||
|
</SnackbarProvider>
|
||||||
|
</UserProfileProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import SignInForm from "@/components/Authentication/SignInForm";
|
import SignInForm from "@/components/Authentication/SignInForm";
|
||||||
|
|
||||||
export default function Index() {
|
export default function Login() {
|
||||||
return <SignInForm />;
|
return <SignInForm />;
|
||||||
}
|
}
|
||||||
+32
-18
@@ -1,8 +1,22 @@
|
|||||||
|
import { useRouter } from "next/router";
|
||||||
import { Typography } from "@mui/material";
|
import { Typography } from "@mui/material";
|
||||||
import { Box } from "@mui/system";
|
import { Box } from "@mui/system";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
|
import LogoutIcon from "@mui/icons-material/Logout";
|
||||||
|
import { deleteCookie } from "cookies-next";
|
||||||
|
|
||||||
export default function Logout() {
|
export default function Logout() {
|
||||||
|
const router = useRouter();
|
||||||
|
const handleLogout = () => {
|
||||||
|
// Remove the cookie
|
||||||
|
deleteCookie("cmc-token");
|
||||||
|
|
||||||
|
// Use replaceState to replace the current URL with the root URL
|
||||||
|
window.history.replaceState({}, document.title, window.location.href);
|
||||||
|
|
||||||
|
// Redirect to the login page
|
||||||
|
router.push("/auth/login");
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="authenticationBox">
|
<div className="authenticationBox">
|
||||||
@@ -20,51 +34,51 @@ export default function Logout() {
|
|||||||
maxWidth: "510px",
|
maxWidth: "510px",
|
||||||
ml: "auto",
|
ml: "auto",
|
||||||
mr: "auto",
|
mr: "auto",
|
||||||
textAlign: "center"
|
textAlign: "center",
|
||||||
}}
|
}}
|
||||||
className="bg-black"
|
className="bg-black"
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
<img
|
<img
|
||||||
src="/images/logo.png"
|
src="/images/logos/wrenchboard-logo.png"
|
||||||
alt="Black logo"
|
alt="Logo"
|
||||||
className="black-logo"
|
className="black-logo"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
src="/images/logo-white.png"
|
src="/images/logos/wrenchboard-logo.png"
|
||||||
alt="White logo"
|
alt="Logo"
|
||||||
className="white-logo"
|
className="white-logo"
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box mt={4} mb={4}>
|
<Box mt={4} mb={4}>
|
||||||
<img src="/images/coffee.png" alt="Coffee" />
|
<LogoutIcon />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Typography as="h1" fontSize="20px" fontWeight="500" mb={1}>
|
<Typography as="h1" fontSize="20px" fontWeight="500" mb={1}>
|
||||||
You are Logged Out
|
Would you like to sign out?
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography>
|
|
||||||
Thank you for using Admash admin template
|
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
href="/auth/sign-in/"
|
onClick={handleLogout}
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{
|
sx={{
|
||||||
mt: 3,
|
mt: 3,
|
||||||
|
backgroundColor: "#4687BA",
|
||||||
textTransform: "capitalize",
|
textTransform: "capitalize",
|
||||||
borderRadius: "8px",
|
borderRadius: "8px",
|
||||||
fontWeight: "500",
|
fontWeight: "500",
|
||||||
fontSize: "16px",
|
fontSize: "16px",
|
||||||
padding: "12px 10px",
|
padding: "12px 10px",
|
||||||
color: "#fff !important"
|
color: "#fff !important",
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: "rgba(70, 135, 186, 0.8)",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Sign In
|
Sign Out
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import SignInForm from "@/components/Authentication/SignInForm";
|
|
||||||
|
|
||||||
export default function SignIn() {
|
|
||||||
return <SignInForm />;
|
|
||||||
}
|
|
||||||
+1
-1
@@ -16,7 +16,7 @@ import TeamMembersList from "@/components/Dashboard/eCommerce/TeamMembersList";
|
|||||||
import BestSellingProducts from "@/components/Dashboard/eCommerce/BestSellingProducts";
|
import BestSellingProducts from "@/components/Dashboard/eCommerce/BestSellingProducts";
|
||||||
import LiveVisitsOnOurSite from "@/components/Dashboard/eCommerce/LiveVisitsOnOurSite";
|
import LiveVisitsOnOurSite from "@/components/Dashboard/eCommerce/LiveVisitsOnOurSite";
|
||||||
|
|
||||||
export default function eCommerce() {
|
export default function ECommerce() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Page title */}
|
{/* Page title */}
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ import ProfileContent from '@/components/Pages/Profile/ProfileContent';
|
|||||||
import ImpressionGoalConversions from "@/components/Dashboard/Analytics/ImpressionGoalConversions";
|
import ImpressionGoalConversions from "@/components/Dashboard/Analytics/ImpressionGoalConversions";
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import styles from '@/styles/PageTitle.module.css';
|
import styles from '@/styles/PageTitle.module.css';
|
||||||
|
import { useUserProfile } from 'contexts/userProfileContext';
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
|
const { state } = useUserProfile();
|
||||||
|
const userProfile = state.userProfile;
|
||||||
|
|
||||||
|
console.log(userProfile)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Page title */}
|
{/* Page title */}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import Axios from "axios";
|
||||||
|
|
||||||
|
class Fetcher {
|
||||||
|
constructor(url) {
|
||||||
|
// this.url = url;
|
||||||
|
// console.log("first request!!!");
|
||||||
|
// return new Response("Working!!!" + url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Endpoints Here
|
||||||
|
// GET /api/
|
||||||
|
|
||||||
|
// POST /api/
|
||||||
|
login(values) {
|
||||||
|
return this.postAuxEnd("/auth/login", values);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------- -----
|
||||||
|
// Unified call below
|
||||||
|
//---------------------------------------- -----
|
||||||
|
|
||||||
|
async getAuxEnd(uri, reqData) {
|
||||||
|
const endPoint =
|
||||||
|
(process.env.AUX_ENDPOINT || "http://localhost:50016/api") + uri;
|
||||||
|
console.log("Checking endpoint get request", endPoint);
|
||||||
|
try {
|
||||||
|
const response = await Axios.get(endPoint);
|
||||||
|
console.log(response.data); // Log the response data if needed.
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
this.handleAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async postAuxEnd(uri, reqData) {
|
||||||
|
const endPoint =
|
||||||
|
(process.env.AUX_ENDPOINT || "http://localhost:50016/api") + uri;
|
||||||
|
console.log("Checking endpoint post request", endPoint);
|
||||||
|
try {
|
||||||
|
const response = await Axios.post(endPoint, reqData);
|
||||||
|
console.log(response.data); // Log the response data if needed.
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
this.handleAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAxiosError(error) {
|
||||||
|
if (error.response) {
|
||||||
|
// Response status is an error code.
|
||||||
|
console.log(error.response.status);
|
||||||
|
} else if (error.request) {
|
||||||
|
// Response not received though the request was sent.
|
||||||
|
console.log(error.request);
|
||||||
|
} else {
|
||||||
|
// An error occurred when setting up the request.
|
||||||
|
console.log(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Fetcher;
|
||||||
@@ -804,6 +804,10 @@ img {
|
|||||||
position: relative;
|
position: relative;
|
||||||
transition: all 0.5s ease-out;
|
transition: all 0.5s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.main-wrapper-content.authBox{
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
.main-wrapper-content.active {
|
.main-wrapper-content.active {
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user