feat(auth): add saveCredentials
method to useAuth0
hook
#1285
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.
Changes
This PR introduces a new public method,
saveCredentials
, to theuseAuth0
hook.This change is important because it enables developers to integrate the
react-native-auth0
SDK with custom authentication flows. Previously, the SDK could only manage credentials obtained through its ownauthorize
method. WithsaveCredentials
, developers can now obtain credentials from an external source (e.g., a custom backend API that performs authentication) and inject them into the SDK's secure storage. Once saved, the SDK can manage the user's session, including refreshing tokens, as if the login had occurred through the standard flow.saveCredentials(credentials: Credentials): Promise<void>
to theAuth0ContextInterface
.saveCredentials
function is now implemented in theAuth0Provider
and exposed through theuseAuth0
hook.References
Fixes #950 ✨
Testing
This change is tested with a new suite of unit tests in
Auth0Provider.spec.tsx
. The tests cover the following scenarios:A successful call to
saveCredentials
correctly invokes the underlyingcredentialsManager.saveCredentials
method with the provided credentials.An error thrown by the
credentialsManager
is caught, dispatched to the Auth0 state, and re-thrown for the caller to handle.The method correctly handles both complete and minimal
Credentials
objects (e.g., without arefreshToken
).This change adds unit test coverage
This change has been tested on the latest version of the platform/language or why not