summaryrefslogtreecommitdiff
path: root/web/frontend/hooks/useAuthenticatedFetch.js
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-16 09:42:10 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-16 09:42:10 +0800
commit672a291c88d1429c29786bca6fe31b89f685a292 (patch)
tree97722bfbfe73baeeaabf4d30655a56c3aa0a3d80 /web/frontend/hooks/useAuthenticatedFetch.js
parent060091e0b1c6d23146cfba720577be5967afcf00 (diff)
Revert "Preparation for CDN hosted version of frontend"
This reverts commit 060091e0b1c6d23146cfba720577be5967afcf00.
Diffstat (limited to 'web/frontend/hooks/useAuthenticatedFetch.js')
-rw-r--r--web/frontend/hooks/useAuthenticatedFetch.js38
1 files changed, 0 insertions, 38 deletions
diff --git a/web/frontend/hooks/useAuthenticatedFetch.js b/web/frontend/hooks/useAuthenticatedFetch.js
deleted file mode 100644
index e5f36a8..0000000
--- a/web/frontend/hooks/useAuthenticatedFetch.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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
- */
-function useAuthenticatedFetch() {
- const app = useAppBridge();
- const fetchFunction = authenticatedFetch(app);
-
- return async (uri, options) => {
- const response = await fetchFunction(uri, options);
- checkHeadersForReauthorization(response.headers, app);
- return response;
- };
-}
-
-function checkHeadersForReauthorization(headers, app) {
- if (headers.get("X-Shopify-API-Request-Failure-Reauthorize") === "1") {
- const authUrlHeader =
- headers.get("X-Shopify-API-Request-Failure-Reauthorize-Url") ||
- `/api/auth`;
-
- const redirect = Redirect.create(app);
- redirect.dispatch(
- Redirect.Action.REMOTE,
- authUrlHeader.startsWith("/")
- ? `https://${window.location.host}${authUrlHeader}`
- : authUrlHeader
- );
- }
-}