koa ctx.redirect not working after fetch request

580 Views Asked by At

I am using ctx.redirect from koa not able to understand why it is not working It is not working in this case

if (shopify && shopify.accessToken) {
      const response = await fetch(
        `https://${shopify.shop}/admin/metafields.json`,
        {
          method: Method.Post,
          headers: {
            [Header.ContentType]: 'application/json',
            'X-Shopify-Access-Token': shopify.accessToken,
          },
        }
      );

      if (response.status === StatusCode.Unauthorized) {
        console.log('after');
        ctx.redirect(routeForRedirect);
        console.log(ctx);
        return;
      }

      await next();
      return;
    }

But working in this case


 if (shopify && shopify.accessToken) {
ctx.redirect(routeForRedirect);  
}
0

There are 0 best solutions below