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>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user