shopify-api-js icon indicating copy to clipboard operation
shopify-api-js copied to clipboard

How do I redirect to my app page after completion of auth/callback

Open kiranupadhyak opened this issue 3 years ago • 1 comments
trafficstars

After the completion of auth/callback, how do I redirect to my app page?. I have named my app as newapp and this the full URL for the app: https://teststore.myshopify.com/admin/apps/newapp-174

router.get('/auth/callback', async(req, res, next) => {
	const shopSession = await Shopify.Auth.validateAuthCallback(
		req,
		res,
		req.query,
	);
	const response = await Shopify.Webhooks.Registry.register({
		path: '/webhooks',
		topic: 'APP_UNINSTALLED',
		accessToken: shopSession.accessToken,
		shop: shopSession.shop,
   	});
	res.redirect(`https://${shopSession.shop}/admin/apps/newapp-174`)
});

In the above code I have hard coded the app URL i.e. admin/apps/newapp-17. Is there any way to avoid it?

kiranupadhyak avatar Mar 11 '22 16:03 kiranupadhyak

I'm not too sure on your set up, but in my case (using the template code from Shopify CLI for Node) this works for me: const host = req.query.host res.redirect(`/?shop=${session.shop}&host=${host}`)

jordanreuser avatar Jul 13 '22 21:07 jordanreuser

Example from the latest version of the app template:

      const host = Shopify.Utils.sanitizeHost(req.query.host);
      const redirectUrl = Shopify.Context.IS_EMBEDDED_APP
        ? Shopify.Utils.getEmbeddedAppUrl(req)
        : `/?shop=${session.shop}&host=${encodeURIComponent(host)}`;

      res.redirect(redirectUrl);

https://github.com/Shopify/shopify-app-template-node/blob/cli_three/web/middleware/auth.js#L59-L64

mkevinosullivan avatar Sep 27 '22 18:09 mkevinosullivan

I'm not too sure on your set up, but in my case (using the template code from Shopify CLI for Node) this works for me: const host = req.query.host res.redirect(`/?shop=${session.shop}&host=${host}`)

@jordanreuser thanks for the your comment. I am also using that one. Which version of the Shopify package are you currently using? We'd like to ensure that you have the most up-to-date features and fixes.

Additionally, are you experiencing any issues with multiple redirections? It's important for us to address any potential challenges you might be facing, so please provide details if you've encountered any problems. Your feedback helps us improve the functionality and reliability of our services. Thank you for your cooperation!

Sky-bits avatar Jan 18 '24 11:01 Sky-bits