Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

NextJS -- Taking advantage of GetServerSideProps

NextJS -- Taking advantage of GetServerSideProps

rustcity
Shopify Partner
13 2 2

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

Replies 2 (2)

rustcity
Shopify Partner
13 2 2

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
    ); 

Hitesh-27
Shopify Partner
1 0 0

Hello @rustcity  I am also facing same problem. I also want to make req using getserversideprop, but not able to find any solution. If you found solution can you please share with me.

Thanks