diff --git a/src/components/auth/AuthProviderWithRedirect.tsx b/src/components/auth/AuthProviderWithRedirect.tsx index 772c645..659b65b 100644 --- a/src/components/auth/AuthProviderWithRedirect.tsx +++ b/src/components/auth/AuthProviderWithRedirect.tsx @@ -2,15 +2,18 @@ import { Auth0Provider } from "@auth0/auth0-react"; import type { FC, PropsWithChildren } from "react"; import { useNavigate } from "react-router-dom"; -const domain = import.meta.env.VITE_AUTH_DOMAIN as string | undefined; -const clientId = import.meta.env.VITE_AUTH_CLIENT_ID as string | undefined; -const redirectUri = import.meta.env.VITE_AUTH_REDIRECT_URL as string | undefined; - -if (!domain || !clientId || !redirectUri) { - throw new Error("Missing environment variables"); -} +type Props = { + domain: string; + clientId: string; + redirectUri: string; +}; -const Auth0ProviderWithRedirect: FC> = ({ children }) => { +const Auth0ProviderWithRedirect: FC> = ({ + children, + domain, + clientId, + redirectUri, +}) => { const navigate = useNavigate(); const onRedirectCallback = async () => { diff --git a/src/main.tsx b/src/main.tsx index a8359bc..8bf73be 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -10,6 +10,23 @@ import LandingPage from "./pages/LandingPage.tsx"; const queryClient = new QueryClient(); +const domain = import.meta.env.VITE_AUTH_DOMAIN as string | undefined; +const clientId = import.meta.env.VITE_AUTH_CLIENT_ID as string | undefined; +const redirectUri = import.meta.env.VITE_AUTH_REDIRECT_URL as string | undefined; + +if (!domain || !clientId || !redirectUri) { + const missing = [ + !domain && "VITE_AUTH_DOMAIN", + !clientId && "VITE_AUTH_CLIENT_ID", + !redirectUri && "VITE_AUTH_REDIRECT_URL", + ] + .filter(Boolean) + .join(", "); + console.warn( + `Missing ${missing}. Auth0 is disabled for this dev session — routes requiring auth will not work. See .env.template.`, + ); +} + const router = createBrowserRouter([ { path: "/", @@ -21,35 +38,43 @@ const router = createBrowserRouter([ ), }, - { - path: "/:envId", - element: ( - - - ( -
- There was an error!{" "} -
{error instanceof Error ? error.message : String(error)}
-
- )} - > - - - - } + ...(domain && clientId && redirectUri + ? [ + { + path: "/:envId", + element: ( + - - - - -
-
-
- ), - }, + + ( +
+ There was an error!{" "} +
{error instanceof Error ? error.message : String(error)}
+
+ )} + > + + + + } + > + + + + +
+
+ + ), + }, + ] + : []), ]); const root = document.getElementById("root");