You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
When I try to redirect the billing url for the app, a loop occurs and status code 302 is returned.
I used redirectOutOfApp function
It works in the development environment, but when the app is deployed to Heroku, it enters a redirect loop and does not proceed to the billing screen.
@shopify/shopify-api version:7.3.1
Node version:18.15.0
Operating system:M1 Mac
// @ts-checkimport{join}from"path";import{readFileSync}from"fs";importexpressfrom"express";importserveStaticfrom"serve-static";importshopifyfrom"./shopify.js";importGDPRWebhookHandlersfrom"./gdpr.js";import{requestBilling}from"./billing.js";constPORT=parseInt(process.env.BACKEND_PORT||process.env.PORT||"3000",10);constSTATIC_PATH=process.env.NODE_ENV==="production"
? `${process.cwd()}/frontend/dist`
: `${process.cwd()}/frontend/`;constapp=express();// Set up Shopify authentication and webhook handlingapp.get(shopify.config.auth.path,shopify.auth.begin());app.get(shopify.config.auth.callbackPath,shopify.auth.callback(),requestBilling,shopify.redirectToShopifyOrAppRoot());app.post(shopify.config.webhooks.path,shopify.processWebhooks({webhookHandlers: GDPRWebhookHandlers}));app.use("/api/*",shopify.validateAuthenticatedSession());app.use(express.json());app.use(shopify.cspHeaders());app.use(serveStatic(STATIC_PATH,{index: false}));app.use("/*",shopify.ensureInstalledOnShop(),requestBilling,async(_req,res,_next)=>{returnres.status(200).set("Content-Type","text/html").send(readFileSync(join(STATIC_PATH,"index.html")));});app.listen(PORT);
billing.js
importshopify,{billingConfig}from"./shopify.js";exportconstrequestBilling=async(req,res,next)=>{console.debug('Start checking billing');constplans=Object.keys(billingConfig);letsession=res.locals.shopify?.session;constisAuth=!session ? false : true;if(!isAuth){session=awaitgetRequestShopSession(shopify.api,shopify.config,req,res);}constisTest=process.env.NODE_ENV!=='production';consthasPayment=awaitshopify.api.billing.check({session, plans, isTest});${shopInfo.planDisplayName}`);if(hasPayment){next();}else{constredirectUri=awaitshopify.api.billing.request({session,plan: plans[0], isTest});if(isAuth){res.redirect(redirectUri);}else{shopify.redirectOutOfApp({
req,
res,redirectUri: redirectUri,shop: shopify.api.utils.sanitizeShop(req.query.shop),});}}};constgetRequestShopSession=async(api,config,req,res)=>{constshop=shopify.api.utils.sanitizeShop(req.query.shop);if(!shop){returnundefined;}config.logger.debug('Checking if shop has installed the app',{
shop
});constsessionId=api.session.getOfflineId(shop);constsession=awaitconfig.sessionStorage.loadSession(sessionId);returnsession;}
Expected behavior
Actual behavior
Steps to reproduce the problem
Create a new shopify/cli node app template.
Add the billing process and deploy the app
Install the application and cancel the billing.
When you open the application again, you will be redirected to the billing page.
The text was updated successfully, but these errors were encountered:
maneko00
changed the title
redirectOutOfApp does not work, causing a billing redirect loop
causing a billing redirect loop
Jul 29, 2023
Issue summary
When I try to redirect the billing url for the app, a loop occurs and status code 302 is returned.
I used redirectOutOfApp function
It works in the development environment, but when the app is deployed to Heroku, it enters a redirect loop and does not proceed to the billing screen.
@shopify/shopify-api
version:7.3.1billing.js
Expected behavior
Actual behavior
Steps to reproduce the problem
The text was updated successfully, but these errors were encountered: