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

Enhance useSaleorExternalAuth to Wrap obtainAccessToken with Error Handling #33

Open
ss-fenil-dave opened this issue Oct 29, 2024 · 0 comments

Comments

@ss-fenil-dave
Copy link

Currently, useSaleorExternalAuth returns an object of type SaleorExternalAuthState, structured as follows:

type SaleorExternalAuthState =
  | { loading: true; authURL?: undefined; error?: undefined }
  | { loading: false; authURL: string; error?: undefined }
  | { loading: false; authURL?: undefined; error: unknown };

Since the SaleorExternalAuth class already provides an obtainAccessToken method, we could simplify the code by creating a function within the hook that wraps this method with error handling. This would allow us to obtain the access token directly from useSaleorExternalAuth, without needing to initialize the class separately, and centralize error management in the hook.

Proposed Solution:

Add a function within useSaleorExternalAuth that wraps obtainAccessToken with error handling.
Return this function from the hook along with the existing state, enabling token access and error handling from the hook itself.

Context: I'm currently upgrading the dashboard app with the newly developed auth-sdk and deprecating the old saleor-sdk. This change would streamline the implementation by managing the error states centrally within the hook.

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

No branches or pull requests

1 participant