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

useAuthenticatedFetch - doc block comment is inaccurate #206

Open
shyleo opened this issue May 13, 2023 · 0 comments
Open

useAuthenticatedFetch - doc block comment is inaccurate #206

shyleo opened this issue May 13, 2023 · 0 comments

Comments

@shyleo
Copy link

shyleo commented May 13, 2023

Issue summary

The comment in useAuthenticatedFetch seems to be inaccurate:

/**
* A hook that returns an auth-aware fetch function.
* @desc The returned fetch function that matches the browser's fetch API
* See: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
* It will provide the following functionality:
*
* 1. Add a `X-Shopify-Access-Token` header to the request.
* 2. Check response for `X-Shopify-API-Request-Failure-Reauthorize` header.
* 3. Redirect the user to the reauthorization URL if the header is present.
*
* @returns {Function} fetch function
*/
export function useAuthenticatedFetch() {

This header is not added, and indeed it should not be - the Access Token should be added on the backend, not from the frontend, if I'm reading Shopify docs correctly. This OAuth tutorial explicitly says that this header is added on the backend, and the App Bridge tutorial says that authenticatedFetch is supposed to add the Session Token under the Authorization header.

Expected behavior

The comment should be rewritten to explain what the function actually does:

  1. It adds an Authorization header to the request, with the value Bearer <Session Token Here>

Actual behavior

Inaccurate comment

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