fix(redirects): move redirects for terms/privacy to client-side redirects#1418
fix(redirects): move redirects for terms/privacy to client-side redirects#1418waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR addresses RSC (React Server Components) CORS issues by migrating redirect handling for the terms of service and privacy policy pages from server-side middleware to client-side React components. The changes maintain the existing whitelabel functionality where deployments can redirect users to external terms/privacy URLs via environment variables (NEXT_PUBLIC_TERMS_URL and NEXT_PUBLIC_PRIVACY_URL).
The core changes involve:
- Middleware Updates: Removed the server-side redirect logic from
middleware.tswhile preserving the route matcher configuration - Client-Side Redirects: Added
useEffecthooks to both/terms/page.tsxand/privacy/page.tsxthat check for configured external URLs and redirect usingwindow.location.href - Security Policy Updates: Enhanced CSP configuration in
csp.tsto allow connections to the redirect target domains - Image Optimization: Added support for brand favicon URLs in Next.js image optimization configuration alongside existing logo URL support
The client-side approach resolves CORS complications that occurred when server-side redirects attempted to navigate to external domains in RSC environments. The fallback behavior remains unchanged - if no external URLs are configured, users see the default terms/privacy content. This solution preserves the whitelabel functionality while eliminating the technical issues that were blocking proper redirect behavior.
Confidence score: 4/5
- This PR addresses a specific technical issue with a well-understood solution that maintains existing functionality
- The changes follow established patterns in the codebase and include proper error handling and URL validation
- Minor attention needed on CSP configuration and middleware route matcher to ensure complete migration consistency
5 files reviewed, 4 comments
Summary
move redirects for terms/privacy to client-side redirects, because we were getting RSC CORS issues
Type of Change
Testing
Tested manually.
Checklist