I’m a new to Shopify app development and trying to get both offline and online token by making a custom app which is made by the cli command “shopify app create node”.
In this app, since I would like to use both Admin and Storefront API, I want to get both offline and online token during the auth process. However, I can’t really understand how could I do that as I can’t find any reference for that process.
FYI: we developed a solution in 2 steps, the first saves the online token, then redirects to the second endpoint. In this second step, we create the offline token and save it.
Thanks so much, this helped me setup my tokens too! I just have one question about the storing process of the offline token in your auth/callback2 route. You run a code snippet that stores the token as follows:
The function Shopify.Auth.validateAuthCallback() stores the session/token for you using your session storage handler, here’s a code snippet of what the function does:
const sessionStored = await Context.SESSION_STORAGE.storeSession(session);
if (!sessionStored) {
throw new ShopifyErrors.SessionStorageError(
'Session could not be saved. Please check your session storage functionality.',
);
}
So what I’m asking is why is there a need to manually store the tokens in your auth functions? I’m very new to shopify so I could have overlooked something.
I need to save the tokens for later access, for example, to access the Shopify APIs. We use MongoDB as data storage, so that’s the way we implemented persistence.
If you have other business requirements and you don’t need to retrieve the tokens later, you can skip that phase.