Refactor to allow gracefully failing if no env file provided#205
Refactor to allow gracefully failing if no env file provided#205Gurpranked merged 2 commits intomainfrom
Conversation
…ns for local development
There was a problem hiding this comment.
Pull Request Overview
This PR refactors environment variable handling to allow the app to gracefully fall back to a local development configuration when a .env file isn’t provided. Key changes include adding an env utility module to check for required env vars, updating navbar components to conditionally render based on env availability, and modifying Cognito configuration and Auth components to support local dev mode.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/utils.js | Added guard clauses in mobile & desktop navbar helpers |
| src/utils/env.js | Introduced utility functions for checking and retrieving env vars |
| src/config/cognito-configure.js | Updated configuration to fall back in local dev mode |
| src/config/cognito-auth-config.js | Replaced direct env access with getEnvVar for consistency |
| src/components/Auth/index.js | Bypasses auth logic when .env.local is missing |
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| // 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(",") : ["", ""]; |
There was a problem hiding this comment.
For consistency with the rest of the codebase, consider using getEnvVar to access 'OAUTH_REDIRECT_SIGN_OUT' instead of directly accessing process.env.
|
Build check completed successfully for feat-graceful-fail-noenv! |
|
The core issue is that the logic checks for a configured environment file which doesn't exist on both the production and dev environment. |
📋 PR Info
Description:
Refactored the code so that if no env file is provided, it assumes a local development environment and gracefully fails to render env value functionality. This is so quick edits can be made to the documentation without needing to touch the authentication related functionality.
Tested
Tested locally, needs to be tested with production env vars to ensure everything still works as before.