added context provider for user profile
This commit was merged in pull request #11.
This commit is contained in:
+38
-5
@@ -1,4 +1,4 @@
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import "../styles/remixicon.css";
|
||||
import "react-tabs/style/react-tabs.css";
|
||||
import "swiper/css";
|
||||
@@ -13,18 +13,51 @@ import "../styles/rtl.css";
|
||||
import "../styles/dark.css";
|
||||
// Theme Styles
|
||||
import theme from "../styles/theme";
|
||||
|
||||
import { SnackbarProvider } from "notistack";
|
||||
import { ThemeProvider, CssBaseline } from "@mui/material";
|
||||
import Layout from "@/components/_App/Layout";
|
||||
import { UserProfileProvider } from "contexts/userProfileContext";
|
||||
import { useRouter } from "next/router";
|
||||
import { hasCookie } from "cookies-next";
|
||||
|
||||
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 (
|
||||
<>
|
||||
<Head>
|
||||
<title>{!hasCookie("cmc-token") && "CMC - auth"}</title>
|
||||
</Head>
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<Layout>
|
||||
<Component {...pageProps} />
|
||||
</Layout>
|
||||
<UserProfileProvider>
|
||||
<SnackbarProvider
|
||||
maxSnack={3}
|
||||
autoHideDuration={2000}
|
||||
preventDuplicate
|
||||
>
|
||||
<Layout>
|
||||
<Component {...pageProps} />
|
||||
</Layout>
|
||||
</SnackbarProvider>
|
||||
</UserProfileProvider>
|
||||
</ThemeProvider>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useRouter } from 'next/router'
|
||||
import { useRouter } from "next/router";
|
||||
import { Typography } from "@mui/material";
|
||||
import { Box } from "@mui/system";
|
||||
import Button from "@mui/material/Button";
|
||||
@@ -6,10 +6,16 @@ import LogoutIcon from "@mui/icons-material/Logout";
|
||||
import { deleteCookie } from "cookies-next";
|
||||
|
||||
export default function Logout() {
|
||||
const router = useRouter()
|
||||
const router = useRouter();
|
||||
const handleLogout = () => {
|
||||
// Remove the cookie
|
||||
deleteCookie("cmc-token");
|
||||
router.push("/auth/login")
|
||||
|
||||
// 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 (
|
||||
<>
|
||||
|
||||
@@ -9,8 +9,13 @@ import ProfileContent from '@/components/Pages/Profile/ProfileContent';
|
||||
import ImpressionGoalConversions from "@/components/Dashboard/Analytics/ImpressionGoalConversions";
|
||||
import Link from 'next/link';
|
||||
import styles from '@/styles/PageTitle.module.css';
|
||||
import { useUserProfile } from 'contexts/userProfileContext';
|
||||
|
||||
export default function Profile() {
|
||||
const { state } = useUserProfile();
|
||||
const userProfile = state.userProfile;
|
||||
|
||||
console.log(userProfile)
|
||||
return (
|
||||
<>
|
||||
{/* Page title */}
|
||||
|
||||
Reference in New Issue
Block a user