Toggling between useOnlineTokens true/false

I have an admin app that was built primarily on useOnlineTokens: true and relies heavily on the associated_user object from that session token. The problem I am having now is with third party services which require the apps token *(offline token).
*
I cannot for the life of me discern away to init runtime with an offline token to capture and then reinit with an online token depending on if an access token exists in storage.

Some architecture insight. We are running on Netlify, database-less (so we actually created a cookie session adapter). But are looking to store the access token inside MongoDB.

But because of shopify.server.js static nature, it has been difficult to find a boolean solution to trigger a reload for useOnlineTokens true/false.

It seems in the docs - that one or the other is the answer. However I wanted to exhaust all solutions before taking a new approach.

Thanks for any input!

@NicholasByDesign ,

You can’t toggle useOnlineTokens at runtime it’s static by design in Shopify.
Instead:

  • Initialize the app once with useOnlineTokens: true
  • Capture and store the offline token at install/reauth (MongoDB is fine)
  • Use online tokens only for admin UI (where associated_user is needed)
  • Use offline tokens for third-party services, webhooks, cron jobs
    Don’t re-init the app.
    Choose which token to use per request, not per app configuration.

That’s the only supported and scalable approach.

Thank you for the reply - I figured it out.