/* GET home page. */ router.get('/', (req, res, next) => { const query = Object.keys(req.query).map((key) => `${key}=${req.query[key]}`).join('&'); if (req.query.shop) { Shop.findOne({ shopify_domain: req.query.shop, isActive: true }, (err, shop) => { if (!shop) { return res.redirect(`/install/?${query}`); } if (verifyOAuth(req.query)) { return res.render('app/app', { apiKey: config.SHOPIFY_API_KEY, appName: config.APP_NAME, shop }); } return res.render('index', { title: req.query.shop }); }); } else { return res.render('index', { title: 'Welcome to your example app' }); } });
router.get('/', (req, res) => { const shopName = req.query.shop; const nonce = generateNonce(); const query = Shop.findOne({ shopify_domain: shopName }).exec(); const shopAPI = new Shopify({ shop: shopName, shopify_api_key: config.SHOPIFY_API_KEY, shopify_shared_secret: config.SHOPIFY_SHARED_SECRET, shopify_scope: config.APP_SCOPE, nonce, redirect_uri: `${config.APP_URI}/install/callback`, }); const redirectURI = shopAPI.buildAuthURL(); query.then((response) => { let save; const shop = response; if (!shop) { save = new Shop({ shopify_domain: shopName, nonce }).save(); } else { shop.shopify_domain = shopName; shop.nonce = nonce; save = shop.save(); } return save.then(() => res.redirect(redirectURI)); }); });
router.get('/callback', (req, res) => { const params = req.query; const query = Shop.findOne({ shopify_domain: params.shop }).exec(); query.then((result) => { const shop = result; const shopAPI = new Shopify({ shop: params.shop, shopify_api_key: config.SHOPIFY_API_KEY, shopify_shared_secret: config.SHOPIFY_SHARED_SECRET,