I am going through this TUT to make a private app in shopify build-a-shopify-app-with-node-and-react
The TUT uses koa but I am using express. Partly because I know express and wanted to see if I could abstract what was going on and apply it in a different context.
When I get to Authenticate and test your app they want one to do this:
Add the HTTPS version of your ngrok forwarding URL and your store’s URL to the following placeholder and load it in a browser:
Tip
Which results in my error:
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type number
at Url.parse (url.js:154:11)
at urlParse (url.js:148:13)
at Object.urlResolve [as resolve] (url.js:659:10)
at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:190:19
at Function.shop (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/server/server.js:28:14)
at middleware (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:168:25)
at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)
at next (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:275:10)
at session (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-session/index.js:468:7)
at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)
This is my server.js:
/* eslint-disable vars-on-top */
require('isomorphic-fetch');
var express = require('express');
var next = require('next');
var ShopifyAuth = require('express-shopify-auth');
var dotenv = require('dotenv');
var session = require('express-session');
dotenv.config();
const port = parseInt(process.env.PORT, 10) || 3000;
var dev = process.env.NODE_ENV !== 'production';
var app = next({ dev });
var { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;
app.prepare().then(() => {
var auth = ShopifyAuth.create({
appKey: SHOPIFY_API_KEY,
appSecret: SHOPIFY_API_SECRET_KEY,
baseUrl: port,
authPath: '/auth',
authCallbackPath: '/auth/callback',
authSuccessUrl: '/success',
authFailUrl: '/fail',
scope: ['read_products'],
shop(req, done) {
return done(null, req.query.shop);
},
onAuth(req, res, shop, accessToken, done) {
// save auth info to session
req.session.shopify = { shop, accessToken };
return done();
},
});
var server = express();
server.use(
session({
secret: SHOPIFY_API_SECRET_KEY,
resave: false,
saveUninitialized: true,
})
);
server.use(auth);
server.get('/success', function(req, res) {
res.json(req.session.shopify);
});
server.get('/fail', function(req, res) {
res.send('Authentication failed');
});
server.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`);
});
});
Anyone have any insight?
You are passing port in baseurl property which is a number. You should add url over there.