Redirect if auth failes

Anonymous
Not applicable
1874 0 0

Hi

I was wondering how I can redirect to a specific page if the authentification fails.

 

For example, if I enter 

 

https://bc686ab571fd.ngrok.io

it should redirect to a specific page

 

https://bc686ab571fd.ngrok.io/auth?shop=example.myshopify.com

Should auth my app

 

  server.use(
    createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET_KEY,
      scopes: ['read_products', 'write_products'],
      async afterAuth(ctx) {
        const { shop, accessToken } = ctx.state.shopify;
        const returnUrl = `${HOST}?shop=${shop}`;
        const subscriptionUrl = await getSubscriptionUrl(accessToken, shop, returnUrl);

        ctx.redirect(subscriptionUrl);

      },
    }),
  );

 

0 Likes