Folks, I'm struggling to have it working, but the ...
# general
f
Folks, I'm struggling to have it working, but the problem is not really SuperTokens but Apollo Server. I'm trying to use subscriptions, following this guide (https://www.apollographql.com/docs/apollo-server/data/subscriptions/#enabling-subscriptions). It "works" but I can't put SuperTokens' session in the context. Any suggestion ?
let me answer myself:
For queries and mutations, I can access the session with this
For Subscriptions: there are no headers/cookies for
ws://
so it can't
verifySession
I just realised I don't really need to access the current user on the subscription resolvers. Just luck.
if you really need that, the key is: create a query that returns the user id and on the client use this ID in the URL for the websocket:
ws://localhost:4000/graphql?user=...
r
hmm. I see. Yea.. websocket auth is totally different. Probably would want to use the session handle instead of the userId
Or a JWT and verify that on each websocket message
n
That approach would work but Apollo subscriptions using web sockets let you pass an additional
connectionParams
that can be accessed in your subscriptions and then added to the context passed to your resolvers. The Apollo documentation contains a small (albeit slightly confusing) example of this: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#operation-context Not sure if thats more complex than what you came up with for your use case, but looks like thats how its intended to work.
10 Views