From 40b63cefef69321489c28fd34d426255e40e8552 Mon Sep 17 00:00:00 2001 From: Gurpranked <93165798+Gurpranked@users.noreply.github.com> Date: Sun, 18 May 2025 10:02:58 -0400 Subject: [PATCH] Revert "Refactor to allow gracefully failing if no env file provided (#205)" This reverts commit 5a01498bdd8ba72d36808c32116892191def8e1c. --- docs/schedule/2024Fall/2024Fall.md | 2 +- src/components/Auth/index.js | 12 ++-------- src/config/cognito-auth-config.js | 14 +++++------- src/config/cognito-configure.js | 12 ---------- src/utils/env.js | 35 ------------------------------ src/utils/utils.js | 11 ++-------- 6 files changed, 10 insertions(+), 76 deletions(-) delete mode 100644 src/utils/env.js diff --git a/docs/schedule/2024Fall/2024Fall.md b/docs/schedule/2024Fall/2024Fall.md index 70e4fef76..a4185a2fb 100644 --- a/docs/schedule/2024Fall/2024Fall.md +++ b/docs/schedule/2024Fall/2024Fall.md @@ -8,7 +8,7 @@ ogDescription: Explore the Fall 2024 meeting schedule for the UMass Lowell Cloud --- :::danger -This schedule is outdated and refers to a past semester. Please check the [latest schedule](../docs/current-schedule) for current information. +This schedule is outdated and refers to a past semester. Please check the [latest schedule](../current-schedule) for current information. ::: diff --git a/src/components/Auth/index.js b/src/components/Auth/index.js index ad29a4488..52793b4c3 100644 --- a/src/components/Auth/index.js +++ b/src/components/Auth/index.js @@ -5,7 +5,6 @@ import React from "react"; import { useAuth } from "react-oidc-context"; import { Redirect, useLocation } from "@docusaurus/router"; import ReactLoading from 'react-loading'; -import { isEnvLocalLoaded } from '../../utils/env'; import { // AUTHENTICATED, @@ -21,15 +20,8 @@ export function AuthCheck({ children }) { let from = location.pathname; const auth = useAuth(); - // If .env.local is missing, skip all auth logic and just render children - if (!isEnvLocalLoaded()) { - return <>{children}; - } - - // Defensive: Only split if OAUTH_REDIRECT_SIGN_OUT is defined - const signOutUris = process.env.OAUTH_REDIRECT_SIGN_OUT ? process.env.OAUTH_REDIRECT_SIGN_OUT.split(",") : ["", ""]; - const [local_logout_uri, prod_logout_uri] = signOutUris; - + const [local_logout_uri, prod_logout_uri] = process.env.OAUTH_REDIRECT_SIGN_OUT.split(","); + const signOutRedirect = () => { const clientId = process.env.CLIENT_ID; const logoutUri = process.env.ENV === "localhost" diff --git a/src/config/cognito-auth-config.js b/src/config/cognito-auth-config.js index 1dfacb64c..22b8be6b1 100644 --- a/src/config/cognito-auth-config.js +++ b/src/config/cognito-auth-config.js @@ -1,15 +1,11 @@ // src/config/cognito-auth-config.js -import { isEnvLocalLoaded, getEnvVar } from '../utils/env'; - const cognitoAuthConfig = { - authority: getEnvVar('AUTHORITY'), - client_id: getEnvVar('CLIENT_ID'), - redirect_uri: getEnvVar('REDIRECT_URI'), - response_type: getEnvVar('OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', 'code'), - scope: getEnvVar('SCOPE', 'email openid phone'), - // Add a flag for local mode - isLocalDev: !isEnvLocalLoaded(), + authority: process.env.AUTHORITY, + client_id: process.env.CLIENT_ID, + redirect_uri: process.env.REDIRECT_URI, + response_type: process.env.OAUTH_REDIRECT_SIGN_RESPONSE_TYPE, + scope: process.env.SCOPE, }; export default cognitoAuthConfig; diff --git a/src/config/cognito-configure.js b/src/config/cognito-configure.js index 119384ed2..ca0291722 100644 --- a/src/config/cognito-configure.js +++ b/src/config/cognito-configure.js @@ -1,20 +1,8 @@ // src/config/cognito-config.js import cognitoAuthConfig from "./cognito-auth-config"; -import { isEnvLocalLoaded } from '../utils/env'; export function configure() { - // If .env.local is missing, fallback to local dev mode and skip config - if (!isEnvLocalLoaded()) { - return { - ...cognitoAuthConfig, - // Optionally, set all sensitive/remote fields to undefined - authority: undefined, - client_id: undefined, - redirect_uri: undefined, - isLocalDev: true, - }; - } // Assuming you have two redirect URIs, and the first is for localhost and // second is for production const [localRedirectURI, prodRedirectURI] = diff --git a/src/utils/env.js b/src/utils/env.js deleted file mode 100644 index 8c0d15292..000000000 --- a/src/utils/env.js +++ /dev/null @@ -1,35 +0,0 @@ -// src/utils/env.js - -// This utility checks for required env vars and provides fallbacks for local dev - -const REQUIRED_ENV_VARS = [ - 'AUTHORITY', - 'CLIENT_ID', - 'REDIRECT_URI', - 'OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', - 'SCOPE', - 'REGION', - 'USER_POOL_ID', - 'USER_POOL_WEB_CLIENT_ID', - 'OAUTH_DOMAIN', - 'OAUTH_REDIRECT_SIGN_OUT', - 'ENV', -]; - -function isEnvLocalLoaded() { - // If any required env var is missing, assume .env.local is not loaded - return REQUIRED_ENV_VARS.every((key) => typeof process.env[key] === 'string' && process.env[key] !== ''); -} - -function getEnvVar(key, fallback = undefined) { - if (typeof process.env[key] === 'string' && process.env[key] !== '') { - return process.env[key]; - } - // Fallback for local dev - if (fallback !== undefined) return fallback; - // Some defaults for local dev - if (key === 'ENV') return 'localhost'; - return undefined; -} - -export { isEnvLocalLoaded, getEnvVar }; diff --git a/src/utils/utils.js b/src/utils/utils.js index fc357c728..b4c2a9901 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -11,13 +11,9 @@ import { LOGOUT_BUTTON, LOGOUT_PATH, } from "./constants"; -import { isEnvLocalLoaded } from './env'; export function useNavbarItemsMobile() { - if (!isEnvLocalLoaded()) { - // If .env.local is missing, do not render auth-related navbar items - return useThemeConfig().navbar.items; - } + // const { route } = useAuthenticator((context) => [context.route]); const auth = useAuth(); let authElement; @@ -65,10 +61,7 @@ export function useNavbarItemsMobile() { } export function useNavbarItemsDesktop() { - if (!isEnvLocalLoaded()) { - // If .env.local is missing, do not render auth-related navbar items - return useThemeConfig().navbar.items; - } + // const { route } = useAuthenticator((context) => [context.route]); const auth = useAuth(); let authElement;