Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/schedule/2024Fall/2024Fall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](../current-schedule) for current information.
This schedule is outdated and refers to a past semester. Please check the [latest schedule](../docs/current-schedule) for current information.
:::


Expand Down
12 changes: 10 additions & 2 deletions src/components/Auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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,
Expand All @@ -20,8 +21,15 @@ export function AuthCheck({ children }) {
let from = location.pathname;
const auth = useAuth();

const [local_logout_uri, prod_logout_uri] = process.env.OAUTH_REDIRECT_SIGN_OUT.split(",");

// 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(",") : ["", ""];
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the codebase, consider using getEnvVar to access 'OAUTH_REDIRECT_SIGN_OUT' instead of directly accessing process.env.

Copilot uses AI. Check for mistakes.
const [local_logout_uri, prod_logout_uri] = signOutUris;

const signOutRedirect = () => {
const clientId = process.env.CLIENT_ID;
const logoutUri = process.env.ENV === "localhost"
Expand Down
14 changes: 9 additions & 5 deletions src/config/cognito-auth-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// src/config/cognito-auth-config.js

import { isEnvLocalLoaded, getEnvVar } from '../utils/env';

const cognitoAuthConfig = {
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,
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(),
};

export default cognitoAuthConfig;
Expand Down
12 changes: 12 additions & 0 deletions src/config/cognito-configure.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
// 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] =
Expand Down
35 changes: 35 additions & 0 deletions src/utils/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 };
11 changes: 9 additions & 2 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import {
LOGOUT_BUTTON,
LOGOUT_PATH,
} from "./constants";
import { isEnvLocalLoaded } from './env';

export function useNavbarItemsMobile() {
// const { route } = useAuthenticator((context) => [context.route]);
if (!isEnvLocalLoaded()) {
// If .env.local is missing, do not render auth-related navbar items
return useThemeConfig().navbar.items;
}
Comment on lines 16 to +20
Copy link

Copilot AI May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for missing env variables is repeated in both mobile and desktop navbar functions. Consider abstracting this logic into a helper function to reduce duplication.

Copilot uses AI. Check for mistakes.
const auth = useAuth();

let authElement;
Expand Down Expand Up @@ -61,7 +65,10 @@ export function useNavbarItemsMobile() {
}

export function useNavbarItemsDesktop() {
// const { route } = useAuthenticator((context) => [context.route]);
if (!isEnvLocalLoaded()) {
// If .env.local is missing, do not render auth-related navbar items
return useThemeConfig().navbar.items;
}
const auth = useAuth();

let authElement;
Expand Down
Loading