NextJS -- Taking advantage of GetServerSideProps

rustcity
Shopify Partner
12 2 1

I'm having a pickle of a time getting access (pun intended) to user session accessTokens in the GetServerSideProps function so as to prepopulate props with page data on page load.

 

I am able to use the server's own offline access token for api calls to work, however I cannot access the logged-in app's scope and use 

 

 

const session = await getSessionToken(app);
console.log("current session: ", session);

 

 

inside the GetServerSideProps function. 

What am I missing?

I'm assuming this is a desired design pattern, rather than making all app queries after page load with session token.

Best,
rustcity

Reply 1 (1)
rustcity
Shopify Partner
12 2 1

Hmm.  K, so because the GetServerSideProps is running on the backend, its' neccessary to pull the session info off the koa context:

 

   const { req, res } = ctx;

    const sessionRetrieved = await Shopify.Utils.loadCurrentSession(
      req,
      res
    );