Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

AppBridgeError shopify

import {
  ApolloClient,
  ApolloProvider,
  HttpLink,
  InMemoryCache,
} from "@apollo/client";
import {
  Provider as AppBridgeProvider,
  useAppBridge,
} from "@shopify/app-bridge-react";
import { authenticatedFetch } from "@shopify/app-bridge-utils";
import { Redirect } from "@shopify/app-bridge/actions";
import { AppProvider as PolarisProvider } from "@shopify/polaris";
import translations from "@shopify/polaris/locales/en.json";
import "@shopify/polaris/build/esm/styles.css";

import { HomePage } from "./components/HomePage";
const shop = "your store code from .env";

export default function App() {
  return (
    <PolarisProvider i18n={translations}>
      <AppBridgeProvider
        config={{
          apiKey: process.env.SHOPIFY_API_KEY,
          shopOrigin: shop,
          forceRedirect: true,
        }}
      >
        <MyProvider>
          <HomePage />
          <p>test</p>
        </MyProvider>
      </AppBridgeProvider>
    </PolarisProvider>
  );
}

function MyProvider({ children }) {
  const app = useAppBridge();

  const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
      credentials: "include",
      fetch: userLoggedInFetch(app),
    }),
  });

  return <ApolloProvider client={client}>{children}</ApolloProvider>;
}

export 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;
    
  };
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: UnhandledPromiseRejectionWarning: MongoNotConnectedError: 
Javascript :: perfect scrollbar in textarea angular 
Javascript :: nextjs build failed optimization killed 
Javascript :: javascript eliminar items repetidos 
Javascript :: angular schematics datatable 
Javascript :: protractor get active element 
Javascript :: Odoo13 How to open a JSON file and read it Avatar arian_shariat@comp.iust.ac.ir 23 February 2021 odoo 
Javascript :: clean up async requests in react useEffect hook using abort controller 
Javascript :: mlutiple css jquery 
Javascript :: sort an array by the laster letter of element javascript 
Javascript :: js get string byte size 
Javascript :: button group get value 
Javascript :: laravel javascript array from blade 
Javascript :: how to set header in angular 8post 
Javascript :: codewars js Get the Middle Character 
Javascript :: trigger key jquery 
Javascript :: jquery create element 
Javascript :: onclick not getting called from dynamic generated data 
Javascript :: express get request origin 
Javascript :: Moment js get first and last day of current month 
Javascript :: get specific item from local storage 
Javascript :: js nested backticks 
Javascript :: jquery input change while typing 
Javascript :: JavaScript does not protect the property name hasOwnProperty 
Javascript :: detect viewport size javascript 
Javascript :: this.$set 
Javascript :: hasOwnProperty with more than one property javascript 
Javascript :: vscode ejs formatter 
Javascript :: useparams remix 
Javascript :: javascript number to number with commas 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =