-
Notifications
You must be signed in to change notification settings - Fork 224
feat: architectural refactor for multi-platform extensibility #1233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Co-authored-by: Arpit Jain <[email protected]> Co-authored-by: snyk-bot <[email protected]>
…act-native-auth0 into SDK-6110-initial-setup
…act-native-auth0 into SDK-6110-initial-setup
…ct-native-auth0 into SDK-6110-core-functionality
… using @auth0/auth0-spa-js
…into SDK-5762-rn-web-support
…instantiation and session management
…ration guide for v5
…s and configuration
…hProvider to use Auth0Client directly and add unit tests for WebWebAuthProvider
…hProvider to use Auth0Client directly and add unit tests for WebWebAuthProvider
gyaneshgouraw-okta
previously approved these changes
Jul 17, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
nandan-bhat
reviewed
Jul 18, 2025
…into refactor_v5
…examples, update documentation, and add redirect handling
- Updated ClassApp to handle errors without logging the error object. - Enhanced Auth0Provider tests to simulate loading states and credential retrieval. - Implemented unimplemented methods in NativeWebAuthProvider to throw AuthError. - Refactored WebAuth0Client to use a singleton pattern for Auth0Client instance. - Improved WebWebAuthProvider to handle redirect callbacks and errors more gracefully. - Added comprehensive tests for WebAuth0Client and WebCredentialsManager to ensure correct behavior. - Created tests for UnimplementedWebAuthenticationProvider to validate error handling. - Added tests for WebCredentialsManager to verify credential management functionality.
…oved interface compliance
…n NativeCredentialsManager
nandan-bhat
approved these changes
Jul 21, 2025
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.
Summary & Motivation
This pull request introduces a major architectural refactor of the
react-native-auth0
library. The primary goal is to evolve from the existing tightly-coupled implementation to a highly abstracted, modular, and extensible architecture that cleanly supports multiple platforms (Native and Web) in a maintainable way.The previous structure made it difficult to add new features or platforms without significant code duplication and risk of regressions. This new architecture establishes a clear separation of concerns, making the library more robust, performant, and easier for future contributors to understand and extend.
The New Architecture
The new design is built on the Dependency Inversion Principle, using a Factory pattern to provide the correct platform-specific implementation at build time. High-level modules (like the React hooks) are now completely decoupled from low-level platform details (the native bridge or
auth0-spa-js
).High-Level Diagram
This diagram illustrates the new flow of control. The key concept is that the consumer-facing API is decoupled from the platform implementations via a Factory that chooses the correct module at build time.
Key Architectural Components
src/core
: The platform-agnostic heart of the library.interfaces
: Defines the "contract" for what our client can do (IAuth0Client
,IWebAuthProvider
, etc.). This is the cornerstone of the abstraction.models
: Concrete data models likeAuth0User
andCredentials
that encapsulate data and related logic (e.g.,isExpired()
).services
: "Orchestrator" classes that contain the business logic for authentication flows (e.g.,CredentialsOrchestrator
handles the token refresh flow).src/platforms
: Contains the platform-specific implementations.native
: The complete module for iOS and Android, containing theNativeBridgeManager
for low-level communication and a set ofadapters
that implement the core interfaces.web
: The complete module for React Native Web, containing a set ofadapters
that wrap the@auth0/auth0-spa-js
library to make it conform to our core interfaces.src/factory
: The "decision-making" layer that runs at build time..ts
,.web.ts
) to ensure the bundler (Metro/Webpack) includes only the code for the target platform. This completely severs the dependency on@auth0/auth0-spa-js
in native builds.src/hooks
&src/index.ts
(Public API):Auth0
class now acts as a simple Facade, which uses the factory to get the correct client. This maintains backward compatibility.Auth0Provider
uses this facade to power theuseAuth0
hook, providing a seamless and performant stateful experience. Issues with UI hanging on logout and infinite re-renders have been fixed.Key Breaking Changes for Users
A full
MIGRATION_GUIDE.md
has been created, but the most critical changes are:camelCase
Properties: Properties on theuser
object are nowcamelCase
(e.g.,user.givenName
instead ofuser.given_name
).expiresAt
Timestamp: TheCredentials
object now provides aexpiresAt
UNIX timestamp instead ofexpiresIn
.AuthError
: All errors are now instances of a single, consistentAuthError
class.authorize
now separate OIDC parameters and SDK options into two distinct arguments:authorize({scope}, {options})
.Testing Strategy
A comprehensive, co-located test suite has been implemented for the new architecture.
__mocks__
directory forreact-native
, creating a clean and stable test environment.How to Review This PR
Given the scope of the refactor, a commit-by-commit review is highly recommended. The commits have been structured logically to tell the story of the new architecture's construction:
feat(core): Introduce foundational types and interfaces...
: Establishes the core contracts.feat(core): Implement core data models and utility functions...
: Adds the reusable building blocks.feat(core): Implement platform-agnostic service orchestrators...
: Introduces the platform-agnostic business logic.feat(factory): Implement platform detector and client factory...
: Builds the platform-selection mechanism.feat(platform): Implement native platform...
: Adds the complete native implementation.feat(platform): Implement web platform...
: Adds the complete web implementation.feat(hooks): Implement public Auth0 facade and update hooks...
: Wires everything up to the consumer-facing API.test: Implement comprehensive test suite...
: Adds all the new tests.