How to make Node-React app use "offline" accessMode?

Highlighted
Shopify Partner
21 2 20

I have developed an app based off the Shopify Node React Demo app. I want to be able to use "offline" access mode in the @shopify/koa-shopify-auth Authorization so that the merchants don't need to re-authenticate each session. But I'm not so sure how to modify the base app to accommodate this.

Here is the relevant bit of code from the package:

app.prepare().then(() => {
  const server = new Koa();
  const router = new Router();
  server.use(session({ sameSite: 'none', secure: true }, server));
  server.keys = [SHOPIFY_API_SECRET_KEY];

  server.use(
    createShopifyAuth({
      apiKey: SHOPIFY_API_KEY,
      secret: SHOPIFY_API_SECRET_KEY,
      accessMode: 'offline',
      scopes: ['read_products', 'write_products'],
      async afterAuth(ctx) {
        const { shop, accessToken } = ctx.session;
        ctx.cookies.set("shopOrigin", shop, {
          httpOnly: false,
          secure: true,
          sameSite: 'none'
        });

Full server code is here. I'm already retrieving the offline access token by using

accessMode: 'offline'

in the ShopifyAuth config.

I am storing the access token into my database. But I'm not sure when and how to use it.

Any guidance would be greatly appreciated!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 166

Hey @FurnaceX 

Once you have the token, you can use it to make API calls on behalf of the merchant. More info: https://shopify.dev/concepts/about-apis/authentication#api-access-modes

Let me know if you have any specific questions.

0 Likes