Sanity Bug 4562#1595
Conversation
… and authentication middleware - Introduced `ORG_CODE_HEADER_NAME` and `TENANT_CODE_HEADER_NAME` in `.env.sample` and `envVariables.js` for better organization and tenant context handling. - Updated `common.js` to include constants for organization and tenant code headers. - Enhanced `authenticator.js` middleware to support organization and tenant code overrides for admin roles, ensuring proper validation and security checks.
WalkthroughThe changes introduce support for organization and tenant code header overrides in the authentication system. Two new environment variables (ORG_CODE_HEADER_NAME and TENANT_CODE_HEADER_NAME) are defined in configuration, exported as constants, and integrated into the authenticator middleware to allow admins to override authentication token fields based on request headers and role permissions. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Authenticator as Authenticator Middleware
participant TokenProcessor as Token Processing
participant Response
Client->>Authenticator: Request with headers<br/>(x-org-code, x-tenant-code)
Authenticator->>Authenticator: Extract user role<br/>from token
alt User has Admin role
Authenticator->>Authenticator: Check if both headers<br/>present
alt Both headers present
Authenticator->>TokenProcessor: Override organization_code<br/>and tenant_code
else Missing header
Authenticator->>Response: Return 400<br/>Bad Request
end
else User has Org Admin role
Authenticator->>TokenProcessor: Override organization_code<br/>only
else No override permission
Authenticator->>TokenProcessor: Skip overrides
end
TokenProcessor->>Response: Return processed token
Response->>Client: Response
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 the current code and only fix it if needed.
Inline comments:
In `@src/constants/common.js`:
- Around line 320-321: The ORG_CODE_HEADER and TENANT_CODE_HEADER constants call
.toLowerCase() on process.env values which can be undefined at module load;
update the assignments for ORG_CODE_HEADER and TENANT_CODE_HEADER in
src/constants/common.js to defensively handle missing env vars by using a safe
default or guard (e.g. use (process.env.ORG_CODE_HEADER_NAME ??
'').toLowerCase() or check typeof before calling toLowerCase()) so the code
never invokes toLowerCase on undefined and optionally surface a clear error if a
required value is missing.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/.env.samplesrc/constants/common.jssrc/envVariables.jssrc/middlewares/authenticator.js
Add organization and tenant code headers to environment configuration and authentication middleware
ORG_CODE_HEADER_NAMEandTENANT_CODE_HEADER_NAMEin.env.sampleandenvVariables.jsfor better organization and tenant context handling.common.jsto include constants for organization and tenant code headers.authenticator.jsmiddleware to support organization and tenant code overrides for admin roles, ensuring proper validation and security checks.