How can I retrieve the offline session token from my database in Shopify App v6?

Hi

I’m using v6 of shopify-app-js. I’ve created both online and offline tokens and stored them in my db.

I’m trying to create an offline session token for use with the graphql client as I’m accessing an endpoint from outside the app (posting data from the storefront to the app), but I can’t see how to get the offline session token from my db?

This >> https://github.com/Shopify/shopify-api-js/blob/main/docs/guides/session-storage.md says to use

const sessionId = await shopify.session.getCurrentId({
  isOnline: true,
  rawRequest: req,
  rawResponse: res,
});

// use sessionId to retrieve session from app's session storage
// getSessionFromStorage() must be provided by application
const session = await getSessionFromStorage(sessionId);

const restClient = new shopify.clients.Rest({session});

I don’t understand this part

const session = await getSessionFromStorage(sessionId);

I can’t see or find how to use / access getSessionFromStorage. I’ve tried pulling it in myself from the db (didn’t work), but I believe you have to generate the session object somehow, and I’m unsure how?

3 Likes

Hi, have you found it?
This is the problem with shopify docs, its soooo INCOMPLETE. you have to figure it our on your own.
Also shopify.session.getCurrentId wont work in the latest node boilerplate it should be shopify.api.session.getCurrentId

4 Likes

Did you guys figure out how to fix this? @StevieW @geobertz

Hi,

Yes but what i did is to use the accessToken from database stored automatically in mongodb session storage.. I think you can create session using the data stored automatically with session storage.

geobertz_0-1679231503953.png

1 Like