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.

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