apollographql / meteor-integration

πŸš€ meteor add apollo
http://dev.apollodata.com/core/meteor.html
108 stars 45 forks source link

Network interface defined server-side + allow login token in config #57

Closed xavxyz closed 7 years ago

xavxyz commented 7 years ago

Hey!

This PR is intended to fix #56.

I've also added the support for a custom loginToken in the config to be able to ssr-ing with an Apollo Client knowing about the current user in its requests.

The Accounts._storedLoginToken fn access to the local storage to grab the token, however as it doesn't exist server-side, we'll be unable to get any token the way it was written before.

The workaround here if someone is doing SSR with apollo meteor package and want to have the current user info pre-loaded is to use fast-render and to pass the cookie meteor_login_token into the meteorClientConfig.

What do you think?

ps: merry christmas πŸŽ„πŸŽ‰

cdmbase commented 7 years ago

@xavcz I just submitted PR for issue #56, didn't noticed yours. But why did you add isSSR which is not related to apollo?

xavxyz commented 7 years ago

Haha, great to see that we want this package to be improved!! πŸŽ‰

I believe you mean ssrMode instead of isSSR? It's an option on the ApolloClient constructor: http://dev.apollodata.com/core/apollo-client-api.html#ApolloClient.constructor

We are using a fork of this package with a similar setup on Nova (Telescope with React & Apollo) and it works great! The Apollo Client exists server-side, and the server-side rendering is done with the current user in the queries linked to the components walked by react-apollo.

xavxyz commented 7 years ago

Hey @lorensr (last time I ping you today, promise πŸ–),

I have to admit I'm pretty glad you didn't merged (or refused 😨 ) this PR yet, I've fixed a pretty annoying bug!

When doing server-side rendering, the cookie could have still be stored even if the user had logged out, causing weird client interactions when a part of the UI depends on the current user (endured for two months on Telescope Nova powered with Apollo).

Note: this PR has been proofed on Nova (i.e. React / Apollo / Meteor app)...it's working great! πŸ‘

xavxyz commented 7 years ago

PR opened on the docs 😊

lorensr commented 7 years ago

Thank you ☺️