init project

This commit is contained in:
2023-07-10 10:48:53 +03:30
parent 75fc37753a
commit 5aeb3f0f64
104 changed files with 11256 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import { NextLinkComposed } from "@/core/components/LinkRouting";
import Message from "@/core/components/Messages";
import useUser from "@/lib/app/hooks/useUser";
import { Button, Typography } from "@mui/material";
import { useTranslations } from "next-intl";
import { useRouter } from "next/router";
const WithAuthMiddleware = ({ children }) => {
const { isAuth } = useUser();
const t = useTranslations();
const router = useRouter();
if (!isAuth)
return (
<Message
text={
<Typography sx={{ textAlign: "center" }}>
{t(
"typography_your_access_to_this_page_has_expired_Please_login_again"
)}
</Typography>
}
actions={
<>
<Button
variant="contained"
component={NextLinkComposed}
to={{
pathname: "/login",
query: { back_url: encodeURIComponent(router.asPath) },
}}
>
{t("login")}
</Button>
</>
}
/>
);
return <>{children}</>;
};
export default WithAuthMiddleware;

View File

@@ -0,0 +1,56 @@
import Message from "@/core/components/Messages";
import useUser from "@/lib/app/hooks/useUser";
import { Stack, Typography } from "@mui/material";
import { useTranslations } from "next-intl";
import { useSearchParams } from "next/navigation";
import { useRouter } from "next/router";
import { useEffect } from "react";
const WithoutAuthMiddleware = ({ children }) => {
const { isAuth } = useUser();
const t = useTranslations();
const router = useRouter();
// gettin url query
const searchParams = useSearchParams();
const backUrlDecodedPath = searchParams.get("back_url");
useEffect(() => {
if (!isAuth) return;
const timer = setTimeout(() => {
router.replace(
backUrlDecodedPath
? decodeURIComponent(backUrlDecodedPath)
: "/dashboard"
);
}, 2000);
return () => {
clearTimeout(timer);
};
}, [isAuth]);
if (isAuth)
return (
<Message
text={
<Stack alignItems="center" spacing={2}>
<Typography sx={{ textAlign: "center" }}>
{t(
"typography_your_login_is_valid_and_you_do_not_need_to_login_again"
)}
</Typography>
<Typography>
{t("typography_redirect_to")}{" "}
{backUrlDecodedPath
? t("typography_routing_previuos_page")
: t("typography_routing_dashbaord_page")}
</Typography>
</Stack>
}
/>
);
return <>{children}</>;
};
export default WithoutAuthMiddleware;