feat: implement runtime authentication handling#1517
Conversation
- Added a new proxy function to manage runtime authentication types and set cookies accordingly. - Introduced runtime authentication configuration to dynamically adjust UI based on the selected auth type. - Updated global styles to hide specific authentication buttons based on the current auth type. - Refactored sign-in button and hero section components to utilize the new runtime authentication logic. - Created a new utility file for runtime authentication configuration and initialization script.
|
@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughA new runtime auth configuration system is introduced. A ChangesRuntime Auth Mode Detection and UI Toggling
Sequence Diagram(s)sequenceDiagram
actor User
participant Browser
participant EdgeMiddleware as proxy (Edge Middleware)
participant Cookie as surfsense_auth_type cookie
participant InitScript as beforeInteractive Script
participant HTML as document.documentElement
participant CSS as globals.css rules
User->>Browser: navigate to page
Browser->>EdgeMiddleware: request (matched route)
EdgeMiddleware->>EdgeMiddleware: resolveRuntimeAuthUiMode(env.AUTH_TYPE, BUILD_TIME_AUTH_TYPE)
EdgeMiddleware->>Cookie: set surfsense_auth_type = GOOGLE | LOCAL
EdgeMiddleware-->>Browser: response with Set-Cookie
Browser->>InitScript: execute before interactive
InitScript->>Cookie: read surfsense_auth_type
InitScript->>HTML: setAttribute data-surfsense-auth-type = GOOGLE | LOCAL
HTML->>CSS: selector html[data-surfsense-auth-type] matches
CSS->>Browser: hide .runtime-auth-local or .runtime-auth-google
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@surfsense_web/proxy.ts`:
- Around line 8-24: Rename the file from proxy.ts to middleware.ts and move it
to the project root directory (or src/ if using a src directory structure).
Next.js middleware requires this specific file name and location to be
automatically recognized and invoked. Additionally, rename the exported function
from proxy to middleware, as Next.js expects the middleware function to be named
exactly middleware. Keep the config export with the matcher as is, since it will
now be properly recognized once the file is in the correct location with the
correct name.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5d458947-79b5-44a2-a179-e9a581ada5d6
📒 Files selected for processing (6)
surfsense_web/app/globals.csssurfsense_web/app/layout.tsxsurfsense_web/components/auth/sign-in-button.tsxsurfsense_web/components/homepage/hero-section.tsxsurfsense_web/lib/runtime-auth-config.tssurfsense_web/proxy.ts
Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR implements a dynamic runtime authentication system that allows switching between Google OAuth and local authentication modes without rebuilding the application. It introduces a cookie-based mechanism (
surfsense_auth_type) to store the authentication preference, uses a client-side initialization script to apply the correct UI mode before hydration, and leverages CSS data attributes with runtime-specific classes (runtime-auth-googleandruntime-auth-local) to conditionally show/hide authentication buttons throughout the application. The changes refactor authentication-related components to render both button types simultaneously while CSS handles the visibility logic.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_web/lib/runtime-auth-config.tssurfsense_web/proxy.tssurfsense_web/app/layout.tsxsurfsense_web/app/globals.csssurfsense_web/components/auth/sign-in-button.tsxsurfsense_web/components/homepage/hero-section.tsxSummary by CodeRabbit
New Features
Refactor