diff --git a/.env b/.env index 12771a9..4a83d86 100644 --- a/.env +++ b/.env @@ -3,6 +3,7 @@ VITE_API_URL=https://dpage-api.danakcorp.com VITE_TOKEN_NAME=dpage-editor-t VITE_REFRESH_TOKEN_NAME=dpage-editor-refresh-t VITE_INVOICE_URL=https://console.danakcorp.com/receipts/ +VITE_LOGIN_URL=https://console.danakcorp.com/auth/login VITE_DESIGN_TIER_1_MAX=10 VITE_DESIGN_PRICE_TIER_1=700000 VITE_DESIGN_TIER_2_MAX=30 diff --git a/src/pages/home/Home.tsx b/src/pages/home/Home.tsx index 13aae7d..1891e68 100644 --- a/src/pages/home/Home.tsx +++ b/src/pages/home/Home.tsx @@ -10,6 +10,7 @@ import { useCreateCatalog } from "@/pages/catalogue/hooks/useCatalogueData"; import { ArrowLeft, DocumentText } from "iconsax-react"; import { useState, type FC } from "react"; import { useNavigate } from "react-router-dom"; +import DirectLogin from "../auth/components/DirectLogin"; const CATALOG_SIZES = [ { id: "a4", label: "A4" }, @@ -51,7 +52,7 @@ const Home: FC = () => {

ساخت کاتالوگ به کمک ویرایشگر داناک

- {/* */} + {import.meta.env.DEV && }
diff --git a/src/router/MainRouter.tsx b/src/router/MainRouter.tsx index f13c728..a0b4775 100644 --- a/src/router/MainRouter.tsx +++ b/src/router/MainRouter.tsx @@ -44,7 +44,7 @@ const MainRouter = () => { + } @@ -52,7 +52,7 @@ const MainRouter = () => { + } @@ -87,7 +87,7 @@ const MainRouter = () => { + } @@ -95,7 +95,7 @@ const MainRouter = () => { + } diff --git a/src/router/PrivateRoute.tsx b/src/router/PrivateRoute.tsx index f1b9a56..e8deae4 100644 --- a/src/router/PrivateRoute.tsx +++ b/src/router/PrivateRoute.tsx @@ -1,29 +1,29 @@ import { useAuth } from '@/context/AuthContext' -import { Paths } from '@/config/Paths' -import { type FC, type ReactNode } from 'react' -import { Navigate, useLocation } from 'react-router-dom' +import { type FC, type ReactNode, useEffect } from 'react' type PrivateRouteProps = { children: ReactNode /** When true (default), user must be logged in to access the route */ requireAuth?: boolean - /** Redirect target when auth is required but user is not logged in */ - redirectTo?: string } const PrivateRoute: FC = ({ children, requireAuth = true, - redirectTo = Paths.home, }) => { const { isAuthenticated, isChecking } = useAuth() - const location = useLocation() + + useEffect(() => { + if (requireAuth && !isChecking && !isAuthenticated) { + window.location.href = import.meta.env.VITE_LOGIN_URL + } + }, [requireAuth, isChecking, isAuthenticated]) if (!requireAuth) { return children } - if (isChecking) { + if (isChecking || !isAuthenticated) { return (
در حال بارگذاری...
@@ -31,10 +31,6 @@ const PrivateRoute: FC = ({ ) } - if (!isAuthenticated) { - return - } - return children } diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 83c199a..da1eaf7 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -5,6 +5,7 @@ interface ImportMetaEnv { readonly VITE_TOKEN_NAME: string; readonly VITE_REFRESH_TOKEN_NAME: string; readonly VITE_INVOICE_URL: string; + readonly VITE_LOGIN_URL: string; readonly VITE_DESIGN_TIER_1_MAX: string; readonly VITE_DESIGN_PRICE_TIER_1: string; readonly VITE_DESIGN_TIER_2_MAX: string;