Offline access tokens are meant for long term access to the store, when no user interaction is involved. This kind of access token is ideal for background work in response to webhooks, or for maintenance work in backgrounded jobs.
I too was stuck on this problem. Thanks to your reply. So basically one needs to store access token offline, which means in a database table, for later used by non-user interactions such as webhooks.
@SAJIDMASOOD Hi, if you’re using the React + Node template provided by Shopify, you can go to the index.js file having the express.js code and make the following changes -
// Set up Shopify authentication and webhook handling
app.get(shopify.config.auth.path, shopify.auth.begin())
app.get(
shopify.config.auth.callbackPath,
shopify.auth.callback(),
async (req, res, next) => {
// retrieve your client session
const client = new shopify.api.clients.Rest({
session: res.locals.shopify.session,
})
const accessToken = client.session.accessToken
console.log("Token => ", accessToken)
try {
saveToMyOwnCustomSolution(accessToken)
} catch (error) {
console.error("Error saving access token:", error)
res.status(500).send("Failed to save token")
}
// Continue with the rest of the callback logic
shopify.redirectToShopifyOrAppRoot()(req, res, next)
}
)