-
Notifications
You must be signed in to change notification settings - Fork 16
Description
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.