Skip to content

fix(android): pass the Auth0 error of a failed renewal to JS - #1754

Open
mroderick wants to merge 1 commit into
auth0:masterfrom
mroderick:fix/android-credentials-error-cause
Open

mroderick wants to merge 1 commit into
auth0:masterfrom
mroderick:fix/android-credentials-error-cause

Conversation

@mroderick

Copy link
Copy Markdown

Changes

On Android, Auth0.Android reports most failed refresh token exchanges as API_ERROR. The bridge rejected with that code only, so an access_denied from a post-login Action and a 5xx from the server reached JS as the same error. iOS already keeps the Auth0 error code.

When getCredentials, getApiCredentials or getSSOCredentials fails with an AuthenticationException cause, the rejection's userInfo now holds that cause's error, error_description and statusCode. Apps read it from error.json.userInfo. type and code do not change, so existing checks for API_ERROR keep working. The JSDoc of CredentialsManagerError documents the keys.

  • The new helper authenticationErrorInfo is in the companion object of A0Auth0Module and takes a map factory, so JVM tests can pass a JavaOnlyMap. The existing passkey helpers use the same pattern.
  • AuthenticationException.getDescription() calls android.text.TextUtils, which plain JVM tests have only as a stub. So android/build.gradle now sets unitTests.returnDefaultValues = true. The existing unit tests do not depend on the stubs and still pass.

This change is Android-only. The iOS bridge already puts the Auth0 error code in code for a failed renewal, but does not pass statusCode or the description.

References

Testing

  • Unit tests: A0Auth0ModuleCredentialsErrorTest checks the three keys for an Auth0 error, and checks for null when the cause is not an Auth0 error or is missing. All Android unit tests pass (:react-native-auth0:testDebugUnitTest).

  • Manual check: I used the mock token endpoint from Android: getCredentials drops the Auth0 error code of a failed renewal, so access_denied cannot be told from a 5xx #1753 with the example app on an Android 16 emulator. Before the change, both responses gave userInfo: null. After the change:

    {"statusCode":403,"error_description":"Denied by a post-login Action","error":"access_denied"}
    {"statusCode":503,"error_description":"Service unavailable","error":"server_error"}
  • Not tested: iOS, because its code is unchanged and I had no Xcode available.

  • This change adds unit test coverage

  • This change has been tested on the latest version of the platform/language or why not

Checklist

Auth0.Android reports most failed renewals and exchanges as API_ERROR, so an access_denied from a post-login Action and a 5xx from the server reached JS as the same error. iOS already keeps the Auth0 error code.

The rejection's userInfo now holds the AuthenticationException cause's error, error_description and statusCode, so apps can read them from error.json.userInfo. The CredentialsManagerError JSDoc documents the keys.

The helper lives in the companion object and takes a map factory, so JVM tests can use JavaOnlyMap. AuthenticationException calls android.text.TextUtils, so the module's unit tests now return default values from the Android stubs.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Android credential retrieval and SSO errors now provide additional Auth0 details, including the error code, description, and HTTP status when available.
  • Documentation
    • Clarified how Android and iOS report Auth0 error details, including what to expect when an HTTP response is unavailable.

The Android bridge now includes Auth0 error details in credential failure rejections when the cause is an AuthenticationException. Tests cover the extracted fields and non-Auth0 causes. Documentation describes the Android and iOS error details.

Changes: Android credential error details

Layer / File(s) Summary
Extract and propagate Auth0 error details
android/src/main/java/com/auth0/react/A0Auth0Module.kt, android/build.gradle, android/src/test/java/com/auth0/react/A0Auth0ModuleCredentialsErrorTest.kt, src/core/models/CredentialsManagerError.ts
A0Auth0Module adds Auth0 error, description, and status code to rejection user info when the cause is an AuthenticationException. Credential retrieval and SSO failures use this data while retaining existing rejection fields. Unit tests cover Auth0 and non-Auth0 causes. Android unit tests return default values for methods backed by Android stubs. The documentation describes Android userInfo and iOS code behavior.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: subhankarmaiti, nandanprabhu, utkrishtsahu

Merge Risk: Minimal · up to 7a7e7

Android credential failures now expose Auth0 error details while the existing error type and code are preserved. The change is additive and low risk, and no merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Android renewal failures now pass the Auth0 error to JavaScript. It matches the changeset, which adds userInfo with error, error_description and statusCode to credenti…
Description check Passed The description states the problem, the new userInfo keys, the helper and its tests, the build.gradle change, the iOS scope, and the linked issue. It matches the changeset closely.
Linked Issues check Passed [#1753] The issue asks that Android pass the Auth0 error code, description and HTTP status of a failed renewal to JS. The issue's Proposal section names the rejection's userInfo as the carrier. At hea…
Out of Scope Changes check Passed All changes connect to #1753. A0Auth0Module.kt adds the authenticationErrorInfo helper and uses it in the credential and SSO rejections. A0Auth0ModuleCredentialsErrorTest.kt tests that helper. android…
Full details: Title check

Explanation

The title names the main change: Android renewal failures now pass the Auth0 error to JavaScript. It matches the changeset, which adds userInfo with error, error_description and statusCode to credential rejections. The title is specific and uses the conventional fix(android) prefix.

Full details: Linked Issues check

Explanation

[#1753] The issue asks that Android pass the Auth0 error code, description and HTTP status of a failed renewal to JS. The issue's Proposal section names the rejection's userInfo as the carrier. At head, A0Auth0Module.kt defines authenticationErrorInfo(cause, newMap). It returns null unless the cause is an AuthenticationException. Otherwise it returns a map with error (getCode()), error_description (getDescription()) and statusCode. The PR summary states that the getCredentials, getApiCredentials and getSSOCredentials rejections pass this map as userInfo, and that type and code are unchanged (API_ERROR). The unit test A0Auth0ModuleCredentialsErrorTest covers the populated map and the null cases. The PR description also reports a manual run on an emulator with the mock endpoint from the issue. That run gave distinct 403 access_denied and 503 server_error details. Limits: the diff read of A0Auth0Module.kt was truncated, so the call-site wiring for getApiCredentials and getSSOCredentials rests on the PR summary and not on a direct read. The Android output uses userInfo.error, while iOS uses code. This follows the issue's Proposal, so it is not treated as a gap.

Full details: Out of Scope Changes check

Explanation

All changes connect to #1753. A0Auth0Module.kt adds the authenticationErrorInfo helper and uses it in the credential and SSO rejections. A0Auth0ModuleCredentialsErrorTest.kt tests that helper. android/build.gradle sets unitTests.returnDefaultValues = true. The PR description gives a concrete reason: AuthenticationException.getDescription() calls android.text.TextUtils, which the plain JVM tests only stub. src/core/models/CredentialsManagerError.ts adds JSDoc that documents the new userInfo keys. The iOS bridge is unchanged, and the PR states this. No unrelated change was found in the reviewed evidence. The A0Auth0Module.kt diff was truncated, so this verdict covers the summarized hunks only.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed due to a network error.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c853d1f and 7a7e7b1.

Files selected for processing: 4

  • android/build.gradle
  • android/src/main/java/com/auth0/react/A0Auth0Module.kt
  • android/src/test/java/com/auth0/react/A0Auth0ModuleCredentialsErrorTest.kt
  • src/core/models/CredentialsManagerError.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@mroderick
mroderick marked this pull request as ready for review November 26, 2026 15:38
@mroderick
mroderick requested a review from a team as a code owner November 26, 2026 15:38

This branch has not been deployed

No deployments
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.

Android: getCredentials drops the Auth0 error code of a failed renewal, so access_denied cannot be told from a 5xx

1 participant