Skip to content

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Aug 21, 2025

This PR adds support for Auth0 Organizations feature to the nextjs-auth0 SDK, allowing developers to specify which organization users should authenticate against. The implementation follows Auth0's ecosystem patterns by removing client-side validation and trusting Auth0's server-side validation, aligning with auth0-spa-js and auth0-react libraries.

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Core Implementation:

  • Added organization parameter support in authorization flow
  • Updated TypeScript types with organization field in User and AuthorizationParameters interfaces

API Changes:

  • handleLogin method now accepts and passes through organization parameter from URL query strings
  • AuthorizationParameters interface includes optional organization field for static configuration
  • User interface includes optional org_id field populated after organization-based authentication

Test Coverage:

  • Comprehensive test suite covering organization parameter pass-through behavior
  • Edge case testing for various organization parameter formats
  • Integration testing with other authorization parameters
  • PAR (Pushed Authorization Requests) compatibility testing

File Changes:
Changed src/server/auth-client.ts: organization parameter pass-through logic
Changed src/types/index.ts: TypeScript definitions for organization support
Added tests/organizations.test.ts: comprehensive organization feature tests
Added tests/organization-parameter-passthrough.test.ts: Auth0 ecosystem alignment validation
Added tests/organizations-live.test.ts: live integration testing capabilities

🎯 Testing

Automated:

  • 20+ unit tests covering organization parameter handling in various scenarios
  • Integration tests with other authorization parameters (audience, scope, returnTo)
  • PAR mode compatibility testing
  • Static configuration vs URL parameter precedence testing
  • Auth0 ecosystem alignment validation tests
  • Parameter validation tests for security (regex patterns, length limits, special characters)
  • Mock authorization server tests for different configurations

Manual:

  1. Set up Auth0 tenant with organizations enabled
  2. Configure SDK with valid Auth0 credentials
  3. Test login flow with ?organization=org_id parameter
  4. Verify organization information appears in user session
  5. Test static organization configuration via authorizationParameters
  6. Confirm organization parameter works alongside other auth parameters

Compatibility:

  • Backward compatible - existing code continues to work unchanged
  • No breaking changes to public APIs
  • Works with both standard and PAR (Pushed Authorization Requests) modes
  • Compatible with all existing authorization parameters

📎 References

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner August 21, 2025 05:13
@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.34%. Comparing base (fe1f5e7) to head (c3e3f9b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2282   +/-   ##
=======================================
  Coverage   85.34%   85.34%           
=======================================
  Files          26       26           
  Lines        2613     2613           
  Branches      481      481           
=======================================
  Hits         2230     2230           
  Misses        377      377           
  Partials        6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tusharpandey13 tusharpandey13 changed the title # Pull Request Description bugfix: Fix 404 error on organization login URLs by adding missing API route handler Aug 21, 2025
@tusharpandey13 tusharpandey13 changed the title bugfix: Fix 404 error on organization login URLs by adding missing API route handler feat: Add organizations Aug 21, 2025
@tusharpandey13 tusharpandey13 marked this pull request as draft August 21, 2025 05:20
@tusharpandey13 tusharpandey13 marked this pull request as ready for review September 5, 2025 12:42
@wwkeyboard
Copy link

🎉 thank you, we were just looking for this today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants