fix: make Google OAuth callback redirect URI configurable - #3
Open
Farheen-H-S wants to merge 1 commit into
Open
Conversation
- Map CALLBACK_URL environment variable in env.js - Update getRedirectUri in auth.controller.js to prioritize CALLBACK_URL with a fallback to localhost - Add CALLBACK_URL placeholder documentation to .env.example
|
@Farheen-H-S is attempting to deploy a commit to the Portify Team on Vercel. A member of the Team first needs to authorize it. |
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.
Description
This Pull Request resolves a limitation in the server-side Google OAuth 2.0 flow by transitioning the hardcoded callback redirect URI to a dynamic configuration.
Root Cause:
Previously, the backend's callback redirect URI was strictly hardcoded to
http://localhost:5000/api/auth/google/callbackinside the authentication controller. This caused redirect URI mismatch errors (redirect_uri_mismatch) when running in production or staging environments, as the value sent to Google during the authorization exchange did not match the actual public/production domains configured in the Google Cloud Console.Solution:
I refactored the redirect URI resolution to dynamically retrieve the production callback URL from a
CALLBACK_URLenvironment variable. If undefined, it gracefully falls back to the local development URI (http://localhost:5000/api/auth/google/callback), ensuring zero friction for developers setting up the project locally.Related Issue
Type of Change
Changes Made
process.env.CALLBACK_URLtoenv.callbackUrlin [env.js] to keep environment variable access unified.getRedirectUriin [auth.controller.js]) to evaluate and returnenv.callbackUrlfirst, falling back to the local callback path.CALLBACK_URLand its default fallback behavior inside [.env.example].Screenshots (if applicable)
Demonstration video shared directly to Hassan via LinkedIn Message showing successful local server boot and error-free redirect to the Google Account Consent screen.
Testing Done
Checklist
Additional Notes
If deploying this to a live/staging environment, remember to add
CALLBACK_URL=https://<your-deployed-backend-domain>/api/auth/google/callbackto your hosting provider's environment variables dashboard and register the matching URI under Authorized redirect URIs in your Google Developer Console project credentials.