-
Notifications
You must be signed in to change notification settings - Fork 341
lazy connect / connectionParams #123
Comments
Thank you for this work @thebigredgeek. I have exactly the same need as you (but for angular-apollo client).
|
@HMLB for my own use case, I don't need a WS connection until after the user has been authenticated... and this is probably best practice in terms of WS security. The |
That's fine. I now use your fork of |
@HMLB hopefully we can get the design change approved soon. I'll finish up by writing tests and docs once that is done. Also currently using my fork :D |
Merged and available in 0.7.0! Thanks @thebigredgeek |
…pollographql#123)" This reverts commit 64cd806.
…ield-resolver Update apollo-server docs
Auth seems to be a big sticking point, as mentioned in several issues:
#33
#75
I am starting to encounter pain with auth, myself. I am building a react-native app where I need to be able to connect the WS only after the user is authenticated to protect the WS server.
Right now, on our web app, I am passing a JWT token (if available) into
connectionParams
and then parsing that token server side... rejecting the connection if the token isn't present or is invalid or belongs to a user who should no longer be able to access our product. This works well for our current build, because we set a cookie and do full page refresh after and so we get a "fresh" network interface that has the ws transport applied to it whenever the token cookie is present.However, with react native, I can't simply "refresh", nor do I really want to as I want to experience to feel fluid as most mobile apps feel.
I need a way to conditionally connect with a dynamic connection param at the time that the user finishes logging in or registering.
My proposal is that we should modify
connectionParams
to accept either an object (as is) or a function that returns an object. IfconnectionParams
is a function, theconnect
call in theSubscriptionClient
constructor is skipped and lazily invoked on the firstsubscribe
call. This would satisfy my case, because I don't reach code that attempts subscriptions until the user is in a state of authentication.I would like to submit a PR for this tomorrow. This is a huge blocker for me right now.
Thanks!
The text was updated successfully, but these errors were encountered: