Re: Shopify App Offline Session Token

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

StevieW
Shopify Partner
12 1 6

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?

 

Want an easy way to open the Shopify Admin for Products, Pages, Collections and more? Use the FREE Shopify Admin Redirect chrome extension.
Replies 3 (3)

geobertz
Shopify Partner
27 0 22

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

geobertz

SteveRlz
Shopify Partner
5 0 6

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

geobertz
Shopify Partner
27 0 22

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

 




geobertz