shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Incorrect return type for userLoggedInFetch in example app

Open jt274 opened this issue 4 years ago • 1 comments

Issue summary

Incorrect return type from userLoggedInFetch provided in example app when using Typescript.

Code in example _app.js

function userLoggedInFetch(app) {
  const fetchFunction = authenticatedFetch(app);

  return async (uri, options) => {
    const response = await fetchFunction(uri, options);

    if (
      response.headers.get("X-Shopify-API-Request-Failure-Reauthorize") === "1"
    ) {
      const authUrlHeader = response.headers.get(
        "X-Shopify-API-Request-Failure-Reauthorize-Url"
      );

      const redirect = Redirect.create(app);
      redirect.dispatch(Redirect.Action.APP, authUrlHeader || `/auth`);
      return null;
    }

    return response;
  };
}

const client = new ApolloClient({
    fetch: userLoggedInFetch(app),
    fetchOptions: {
      credentials: "include",
    },
  });

Expected behavior

null is not an accepted return type for the ApolloClient fetch. If the return null line is omitted, then when the app needs to re-auth it throws errors because it takes a second to redirect and tries to run the graphql query in the meantime. There should be an accepted return type of Response that does not allow the query to proceed, or another method to simply not allow the userLoggedInFetch function to complete, and fully execute the redirect.

Actual behavior

With return null line present, Typescript throws error: Type 'null' is not assignable to type 'Response'.

jt274 avatar Apr 22 '21 03:04 jt274

Thanks for pointing this out, we'll look into it! I've experienced the issue with removing the return null myself, but we'll see if we can fix the return type.

paulomarg avatar Apr 22 '21 13:04 paulomarg

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

github-actions[bot] avatar Oct 22 '22 02:10 github-actions[bot]