mongodb / stitch-js-sdk

MongoDB Stitch JavaScript SDK
Apache License 2.0
113 stars 67 forks source link

How to handle user session between server sdk and browser sdk in Isomorphic app Like Next.js #273

Open faisalahmedansari20 opened 5 years ago

faisalahmedansari20 commented 5 years ago

As we have discussed in #267 about how can we use stitch sdk in isomorphic app like Next.js . Now problem is that when user login first time it is obvious that browser sdk will store user credential at browser local storage.

But after login when, I refresh my page. On server inside getInitialProps() function it shows that user is not logged In. I think that is because App server does not know anything about user and its credential. And credential are at user side in browser local storage.

So my question is how can i handle such scenario?

or other scenario could be when user comes back and access my app. Server will assume user is not logged in and throw user on login page.

adamchel commented 5 years ago

Hi @faisalahmedansari20,

Unfortunately, we do not yet have an SDK that explicitly supports isomorphic apps with frameworks like Next.js or Nuxt.js. This is something we plan on investigating in the near future, but I can't give any more specifics. We'll keep you updated with any new developments, and I'll leave this issue open until we have a solution.

efleurine commented 5 years ago

My best bet (I did not try it yet) would be to associate a API Key to everyone user and send that with cookies to the server.