Comments (4)
As the error says, in your code there doesn't seem to be a call to Shopify.Context.Initialize()
. You should take a look at https://github.com/Shopify/shopify-api-node/blob/main/docs/getting_started.md#set-up-context for details. If you didn't have this before in your code, you may have been using an older version of the Shopify API library.
from simple-koa-shopify-auth.
@TheSecurityDev Thank a lot, I test this and let you know
from simple-koa-shopify-auth.
I added as suggested but get the following error on npm start now.
Cannot read properties of undefined (reading 'initialize')
at Object. (C:\xampp_7\htdocs\shopify_Server_upload\shopifyappnew\server.js:24:17)
If I use import, its giving me ES6 syntax error "cannot use import outside modules". so I changed the syntax as below.
`require('isomorphic-fetch');
const dotenv = require('dotenv');
const Koa = require('koa');
const next = require('next');
const session = require('koa-session');
dotenv.config();
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handle = app.getRequestHandler();
const {SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY} = process.env;
const {createShopifyAuth} = require("simple-koa-shopify-auth");
const {verifyRequest} = require("simple-koa-shopify-auth");
const verifyApiRequest = verifyRequest({returnHeader: true});
const verifyPageRequest = verifyRequest();
const Shopify =require ('@shopify/shopify-api');
const { ApiVersion }=require ('@shopify/shopify-api');
const {API_KEY, API_SECRET_KEY, SCOPES, SHOP, HOST, HOST_SCHEME} = process.env;
Shopify.Context.initialize({
API_KEY,
API_SECRET_KEY,
SCOPES: [SCOPES],
HOST_NAME: HOST.replace(/https?:///, ""),
HOST_SCHEME,
IS_EMBEDDED_APP: true,
API_VERSION: ApiVersion.version // all supported versions are available, as well as "unstable" and "unversioned"
});
app.prepare().then(() => {
const server = new Koa();
server.use(session({secure: true, sameSite: 'none'}, server));
server.keys = [SHOPIFY_API_SECRET_KEY];
server.use(
createShopifyAuth({
apiKey: SHOPIFY_API_KEY,
secret: SHOPIFY_API_SECRET_KEY,
scopes: ['read_orders,write_orders,read_shipping,read_products,write_products'],
accessMode: 'offline',
authPath: "/auth", // Where to redirect if the session is invalid
async afterAuth(ctx) {
const {shop, accessToken} = ctx.state.shopify;
// ctx.cookies.set('shopOrigin', shop, {httpOnly: false});
// ctx.cookies.set('shopOrigin', shop, {httpOnly: false,secure: true,sameSite: 'none'});
const axios = require('axios');
const https = require('https');
// return this promise
const agent = new https.Agent({
rejectUnauthorized: false
});
await axios.get('https://qikink.com/erp2/index.php/login/shopify?json=1&shop=' + shop + "&accesstoken=" + accessToken, {httpsAgent: agent}).then((response) => {
// console.log('got response' + res);
if (response['data'].error) {
console.log("Below is the error");
console.log(response['data'].error);
return ctx.redirect("/");
// ctx.redirect("/");
// return ctx.redirect('https://qikink.com/erp2/index.php/login/shopify?json=0&shop=' + shop + "&accesstoken=" + accessToken);
} else {
console.log("No Error");
console.log(response);
return ctx.redirect("/");
}
});
console.log("why coming here");
},
}),
);
server.use(verifyRequest());
server.use(async (ctx) => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
ctx.res.statusCode = 200;
return;
});
server.listen(port, () => {
console.log(`> Ready on http://localhost:${port}`);
});
});
`
Below is my env file.
SHOPIFY_API_KEY=xxx
SHOPIFY_API_SECRET_KEY=xx
API_KEY=xx
API_SECRET_KEY=xx
SCOPES=read_orders,write_orders,read_shipping,read_products,write_products
SHOP=shopifyapp.qikink.com
HOST_SCHEME=https
HOST=localhost
from simple-koa-shopify-auth.
This is my package.json , should i include shopify-api here.
{
"name": "qikink-dropshipping",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/plugin-transform-react-jsx": "^7.19.0",
"@shopify/app-bridge": "^1.26.2",
"@shopify/app-bridge-react": "^1.26.2",
"@shopify/polaris": "^4.27.0",
"@zeit/next-css": "^1.0.1",
"asset-require-hook": "^1.2.0",
"axios": "^0.19.2",
"axios-curlirize": "^1.3.5",
"babel-preset-env": "^1.7.0",
"dotenv": "^8.2.0",
"esm": "^3.2.25",
"express": "^4.17.1",
"form-data": "^3.0.0",
"isomorphic-fetch": "^2.2.1",
"js-cookie": "^2.2.1",
"koa": "^2.13.0",
"koa-session": "^5.13.1",
"next": "^9.5.2",
"nohup": "^0.1.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-string-replace": "^0.4.4",
"request": "^2.88.2",
"request-ip": "^2.1.3",
"simple-koa-shopify-auth": "^2.1.5",
"sqlite3": "^5.1.2",
"typescript": "^3.9.7"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6"
}
}
from simple-koa-shopify-auth.
Related Issues (16)
- App bridge error after redirect in pages HOT 1
- Latest version (2.1.4) doesn't use the host param when calling createApp in top-level-oauth-redirect.ts HOT 3
- ReferenceError: btoa is not defined HOT 5
- Supporting latest version of `@shopify/shopify-api` (version 6) HOT 13
- How to make it work with koa-mount? HOT 2
- Validate the request from Frontend
- Shopify graphQL proxy HOT 4
- LRUCache is not a constructor HOT 3
- Session creation is not working HOT 9
- The host is undefined HOT 12
- Reauth on Client Side HOT 2
- Add the ability to specify the host of the redirect url instead of ctx.host HOT 7
- "The app couldn't be loaded" error HOT 12
- Shopify.utils.validateShop has been deprecated HOT 3
- "Internal Server Error" message when first time installed an app, but app works fine after reload page. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-koa-shopify-auth.