Skip to content

Enhance useSaleorExternalAuth to Wrap obtainAccessToken with Error Handling #33

@ss-fenil-dave

Description

@ss-fenil-dave

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions