Development discussions around Shopify APIs
Contrary to the docs, the code below always generates a short lived access token that changes every 24hrs. I've included accessMode: 'offline' even though that is supposedly the default.
Is there some restriction/setting I'm not aware of as to why I can generate an offline token?
Server.js
require('isomorphic-fetch') const { Account } = require('./db.js') const { ApiVersion } = require('@shopify/koa-shopify-graphql-proxy') const { default: createShopifyAuth } = require('@shopify/koa-shopify-auth') const { default: graphQLProxy } = require('@shopify/koa-shopify-graphql-proxy') const { v4: uuidv4 } = require('uuid') const { verifyRequest } = require('@shopify/koa-shopify-auth') const dotenv = require('dotenv') const Koa = require('koa') const logger = require('koa-logger') const next = require('next') const session = require('koa-session') const store = require('store-js') 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 app.prepare().then(() => { const server = new Koa() server.use(logger()) 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_products', 'read_inventory', 'write_inventory', 'read_locations', ], accessMode: 'offline', async afterAuth(ctx) { try { const { shop, accessToken, _expire } = ctx.session console.log('HERE', shop, accessToken, _expire)
Package.json
"dependencies": { "@shopify/app-bridge-react": "^1.24.0", "@shopify/koa-shopify-auth": "3.1.64", "@shopify/koa-shopify-graphql-proxy": "^4.0.1", "@shopify/polaris": "^4.26.1", "@zeit/next-css": "^1.0.1", "apollo-boost": "^0.4.9", "dotenv": "^8.2.0", "graphql": "^15.1.0", "isomorphic-fetch": "^2.2.1", "js-cookie": "^2.2.1", "koa": "^2.13.0", "koa-logger": "^3.2.1", "koa-session": "^6.0.0", "mysql2": "^2.1.0", "next": "^9.4.4", "qrcode.react": "^1.0.0", "react": "^16.13.1", "react-apollo": "^3.1.5", "react-dom": "^16.13.1", "sequelize": "^5.21.13", "store-js": "^2.0.4", "uuid": "^8.1.0" },
User | RANK |
---|---|
10 | |
6 | |
5 | |
5 | |
5 |
Learn these 5 things I had to learn the hard way with starting and running my own business
By Kitana Jan 27, 2023Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...
By Gabe Jan 6, 2023How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...
By Skye Dec 30, 2022