Skip to content
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

Platform-agnostic errors and types #923

Open
5 tasks done
thyming opened this issue Jun 17, 2024 · 0 comments
Open
5 tasks done

Platform-agnostic errors and types #923

thyming opened this issue Jun 17, 2024 · 0 comments
Labels
feature request A feature has been asked for or suggested by the community

Comments

@thyming
Copy link

thyming commented Jun 17, 2024

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

I would like to be able to handle common and expected errors in the auth flow gracefully. For example, if the user closes the login popup, this throws an error, or if a refresh token is expired, this throws an error. However, the error codes and structures are undocumented, platform-specific, and untyped in typescript.

Describe the ideal solution

The error object returned by useAuth0 should be a typed error object with enumerated error codes that are not platform-specific except when strictly necessary. The react SDK does something like this without having the typed error codes, but at least you can reference the oauth error codes from the spec.

One can imagine at least two error classes that this library could implement:

  • OAuth error, exactly like the react one, bonus points for enumerating some of the more common spec'ed codes
  • CredentialsManager error, perhaps containing an OAuth error as a cause (e.g. refresh token expiration from the server), or something else related to retrieval

Alternatives and current workarounds

The current workaround that we use in our codebase is that we have inspected errors that come out in these cases and reverse engineered the error API from that.
Something like:

error && 'code' in error && (error.code === 'a0.session.user_cancelled' || error.code === 'USER_CANCELLED')

which feels quite brittle as an undocumented, platform-specific API.

Additional context

No response

@thyming thyming added the feature request A feature has been asked for or suggested by the community label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

1 participant