fix: handle undefined values in onboarding components#246
Merged
Conversation
- Replace || with ?? in AuthCallbackContent.tsx - Replace || with ?? in UserInputArea.tsx - Replace || with ?? in GoogleOAuthButton.tsx - Replace || with ?? in AddressAutocomplete.tsx - Replace || with ?? in publicApiSlice.ts - Replace || with ?? in axiosBaseQuery.ts - Fix useEffect dependency in AddressAutocomplete.tsx - Remove console.log statements in AuthCallbackContent.tsx
- Create unified getApiBaseUrl() utility function - Remove hardcoded localhost fallbacks from all files - Production environment now requires API URL to be configured - Development environment allows localhost fallback with warning - Improves code quality and prevents production misconfigurations Files updated: - src/utils/api-config.ts (new) - src/services/places.ts - src/lib/axiosBaseQuery.ts - src/features/public/publicApiSlice.ts - src/components/GoogleOAuthButton.tsx - src/app/(public)/blogs/page.tsx - src/app/(public)/blogs/components/BlogList.tsx - src/app/(public)/blogs/[id]/page.tsx
- Remove unnecessary NEXT_PUBLIC_API_BASE_URL fallback - Use only NEXT_PUBLIC_API_URL as it's the actual configured variable - Simplify code and error messages
- Change from NEXT_PUBLIC_API_URL to NEXT_PUBLIC_API_BASE_URL - This matches the actual configured environment variable name
- Keep same behavior as before: NEXT_PUBLIC_API_BASE_URL ?? localhost fallback - Remove production environment check to match original usage - Environment variable name unchanged: NEXT_PUBLIC_API_BASE_URL - Function only provides centralized management, no behavior change
…upport - Restore NEXT_PUBLIC_API_BASE_URL and NEXT_PUBLIC_API_URL support - Keep function for centralized management - Match original behavior exactly
- Replace getApiBaseUrl() with process.env.NEXT_PUBLIC_API_BASE_URL - Ensure environment variable names match main branch exactly
- Change 'next dev -p 3000' back to 'next dev' to match main branch
…access - Replace all direct process.env.NEXT_PUBLIC_API_BASE_URL usage with getApiBaseUrl() - Centralize API base URL logic in api-config.ts - Improve code consistency and maintainability
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized getApiBaseUrl() utility function and enhances undefined value handling in onboarding components, particularly in AddressAutocomplete and UserInputArea. It also adds validation for OAuth callback data to prevent invalid user data from being processed.
Key Changes:
- Created
getApiBaseUrl()utility function for consistent API URL management across the codebase - Updated component prop types to accept
undefinedvalues with appropriate guards and default values - Added validation in OAuth callback to verify user data contains required
_idandemailfields
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/api-config.ts |
New utility function to centralize API base URL retrieval with fallback default |
src/services/places.ts |
Refactored to use getApiBaseUrl() instead of direct environment variable access |
src/lib/axiosBaseQuery.ts |
Refactored to use getApiBaseUrl() and improved nullish coalescing for method parameter |
src/features/public/publicApiSlice.ts |
Updated to use centralized getApiBaseUrl() utility |
src/components/ui/AddressAutocomplete.tsx |
Enhanced undefined handling for value prop, improved address formatting with validation, and added null guards |
src/components/GoogleOAuthButton.tsx |
Simplified API URL retrieval using getApiBaseUrl() utility |
src/app/onboarding/components/UserInputArea.tsx |
Updated to handle undefined userInput prop with appropriate guards and default values |
src/app/auth/callback/AuthCallbackContent.tsx |
Added validation for OAuth user data and default values for optional fields |
src/app/(public)/blogs/page.tsx |
Refactored to use getApiBaseUrl() for API calls |
src/app/(public)/blogs/components/BlogList.tsx |
Updated to use centralized API URL utility function |
src/app/(public)/blogs/[id]/page.tsx |
Simplified API URL retrieval using getApiBaseUrl() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR handles undefined values in onboarding components and improves error handling.
Changes
Environment Variables